Skip to content

Multiple databases in a single isolate #3147

Answered by simolus3
Airyzz asked this question in Q&A
Discussion options

You must be logged in to vote

Currently, I have one isolate per database, but I am wondering if it is possible to just use a single isolate, with all databases on the same isolate?

This is what I came up with. It uses unreleased drift APIs to cleanup unused servers, you'd have to remove the beforeShutdown and shutdownAfterLastDisconnect parameters before drift 2.20 is out (hopefully soon):

final class MultiDatabaseServer {
  final Map<String, DriftIsolate> _activeIsolates = {};
  final ReceivePort _receiveConnections = ReceivePort();

  MultiDatabaseServer() {
    _receiveConnections.listen((message) {
      if (message is (String, SendPort)) {
        final name = message.$1;
        final isolate = _activeIsolates.p…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Airyzz
Comment options

Answer selected by Airyzz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants