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

support running inside of a worker thread #37

Closed
wants to merge 4 commits into from
Closed

support running inside of a worker thread #37

wants to merge 4 commits into from

Conversation

SimenB
Copy link
Contributor

@SimenB SimenB commented Jan 22, 2019

Hey! 👋

Jest uses this module to write cached files to disk from within workers. It works great with child_process.spawn, but it doesn't work from within worker_threads due to process.pid being shared between the main thread and all its workers.

This PR will check if it's being run from within a worker, and if so, use worker_threads.threadId, which should be unique.

I've put together an example over in jestjs/jest#7680 whch shows process.pid being identical. We're super close to a release, so for now I've just copied over the source from this project into our own module - would love for you to merge this (or otherwise fix it), though! 🙂

index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
@iarna
Copy link
Contributor

iarna commented Jan 22, 2019

This seems pretty reasonable to me, I'll look about landing this today!

@iarna
Copy link
Contributor

iarna commented Jan 22, 2019

This is landed and been released in 2.4.0!

@iarna iarna closed this Jan 22, 2019
@SimenB SimenB deleted the worker-support branch January 22, 2019 23:56
@SimenB
Copy link
Contributor Author

SimenB commented Jan 22, 2019

Awesome, thank you very much @iarna!

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

Successfully merging this pull request may close these issues.

4 participants