Closed theunsa closed 1 month ago
Hey @theunsa
The sync plugin needs to be imported and installed in the worker, not on the main thread. Something like:
// ../public/pglite-worker.js
import { PGlite } from '@electric-sql/pglite'
import { worker } from '@electric-sql/pglite/worker'
import { electricSync } from '@electric-sql/pglite-sync'
worker({
async init(options) {
console.log('worker init: options', options)
const pglite = new PGlite({
...options,
extensions: {
sync: electricSync()
{
})
console.log('worker init: pglite', pglite)
return pglite
},
})
In general you can't pass through extensions from the main thread to the worker as they are js functions and can't be sterilised and transferred.
Note: There is the issue currently that having the sync plugin on the worker thread prevents you from calling sync methods from the main thread. I am working on that, we will make the stink methods available on both threads soon.
Hi @samwillis
"sterilised" ... LOL ... intended or not, that pun is funny
Thanks for pointing that out, it makes total sense and works.
Existing main-thread-sync-block issue noted, I'll watch our for your fix but there is enough to still play with in mean time.
main script
../public/pglite-worker.js
deps
The above works fine for
pglite-sync
v0.2.7 but the PGliteWorker creation step never even calls the workerinit()
for v0.2.8 and greater.Another way to obviously test is to remove the extension
electric: electricSync(),
line from theoptions
then v0.2.8 and greater creates the PGliteWorker fine.If there is any additional debugging I can enable to help trace the issue please let me know.