powersync.dart icon indicating copy to clipboard operation
powersync.dart copied to clipboard

WIP: Use sync worker

Open simolus3 opened this issue 1 year ago • 0 comments

This offloads the task of synchronizing databases to a separate worker, allowing it to be coordinated across tabs even when the database itself is not in a shared worker.

To test this, compile sync_worker.dart with dart2js and put it into web/ of an example project as powersync_sync.worker.js. The web database will try to use the shared sync worker, but fall back to the existing implementation if that doesn't work. This uses the new exposeEndpoint method introduced in https://github.com/powersync-ja/sqlite_async.dart/pull/63, giving the sync worker efficient access to the opened database. Requests to upload data and to fetch tokens are forwarded to a connected client. One thing not yet implemented: The sync worker currently only uses the database connection established by the first tab. When multiple tabs connect to the worker and the first one closes, we'll have to setup a new sync implementation backed by a new tab.

simolus3 avatar Sep 18 '24 20:09 simolus3