workerMainForOpen static method

void workerMainForOpen(
  1. {WasmDatabaseSetup? setupAllDatabases}
)

The entrypoint for a web worker suitable for use with open.

Generally, you can grab a pre-compiled worker file from a drift release and don't need to call this method in your app.

If you prefer to compile the worker yourself, write a simple Dart program that calls this method in its main() function and compile that with dart2js. This is particularly useful when using setupAllDatabases, a callback that will be invoked on every new CommonDatabase created by the web worker. This is a suitable place to register custom functions.

Implementation

static void workerMainForOpen({
  WasmDatabaseSetup? setupAllDatabases,
}) {
  final self = globalContext;

  if (self.instanceOfString('DedicatedWorkerGlobalScope')) {
    DedicatedDriftWorker(
            self as DedicatedWorkerGlobalScope, setupAllDatabases)
        .start();
  } else if (self.instanceOfString('SharedWorkerGlobalScope')) {
    SharedDriftWorker(self as SharedWorkerGlobalScope, setupAllDatabases)
        .start();
  }
}