close
The Wayback Machine - https://web.archive.org/web/20201024065451/https://github.com/sindresorhus/electron-store/issues/111
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use in Worker Threads #111

Open
shellscape opened this issue Apr 27, 2020 · 2 comments
Open

Use in Worker Threads #111

shellscape opened this issue Apr 27, 2020 · 2 comments

Comments

@shellscape
Copy link

@shellscape shellscape commented Apr 27, 2020

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 electron@8.1.0 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

const defaultCwd = (electron.app || electron.remote.app).getPath('userData');
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.

@sindresorhus
Copy link
Owner

@sindresorhus sindresorhus commented Apr 27, 2020

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.

@shellscape
Copy link
Author

@shellscape shellscape commented Apr 27, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.