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.


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

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