electron-store icon indicating copy to clipboard operation
electron-store copied to clipboard

Use in Worker Threads

Open shellscape opened this issue 4 years ago • 2 comments

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.

shellscape avatar Apr 27 '20 03:04 shellscape

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.

sindresorhus avatar Apr 27 '20 03:04 sindresorhus

I've gone down the rabbit hole of SharedArrayBuffer and will share what I find, but that would still rely upon port.postMessage.

shellscape avatar Apr 27 '20 03:04 shellscape