Describes the topology between clients (e.g. tabs) and the drift web worker when spawned with connectToDriftWorker.
- dedicated → const DriftWorkerMode
This worker, which we expect is a Dart program calling driftWorkerMain in its
Starts a SharedWorker that is used across several browsing contexts (e.g. tabs or even a custom worker you wrote).
This shared worker, which we expect is a Dart program calling driftWorkerMain in its
So, while every tab uses its own connection, they all connect to the same shared worker. Thus, every tab has a view of the same logical database. Even stream queries are synchronized across all tabs.
Note that shared worker may not be supported in all browsers.
However, a technical difference is that the actual database is not opened in the shared worker itself. Instead, the shared worker creates a new Worker internally that will host the database and forwards incoming connections to this worker. Generally, it is recommended to use a shared worker. However, some database connections, such as the one based on the Origin-private File System web API, is only available in dedicated workers. This setup enables the use of such APIs.
Note that only Firefox seems to support spawning dedicated workers in shared workers, which makes this option effectively unsupported on Chrome and Safari.