electron-store
electron-store copied to clipboard
Use in Worker Threads
I highly suspect that this is going to be the same answer as #82 with a worker_thread
specific quasi-solution similar to #110, but I haven't seen this asked yet, so I figured I would toss it out there.
I'm using [email protected] and native worker_thread
is available without any magic on that version. (For those not aware and reading this issue, Node worker_threads
are different from Web Workers
available in the Render Process in electron) When attempting the following in a new worker:
import Store from 'electron-store';
const store = new Store();
The package will throw an error on this line https://github.com/sindresorhus/electron-store/blob/f4673e0f30668e49658e332307cc1443cc1c3818/index.js#L8 of Cannot read property 'app' of undefined
.
I'd wager that it's got something to do with a different memory space, but I don't know enough about worker threads yet to say. And I was curious if there was a workaround available that didn't involve using the worker and parent port messaging.
I assume this is because the worker thread runs as a Node.js environment and not Electron environment. I couldn't find any docs on this however.
I've gone down the rabbit hole of SharedArrayBuffer
and will share what I find, but that would still rely upon port.postMessage
.