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

Implement workers utility #22

Closed
wants to merge 1 commit into from

Conversation

jasnell
Copy link
Contributor

@jasnell jasnell commented Mar 31, 2020

Provides a utility that can be used to determine if the current thread
is the main Node.js thread or a worker thread, even if worker threads
are not supported.

const { workers } = require('@nearform/node-clinic-common')

console.log(workers.isMainThread)
console.log(workers.threadId)

If workers are not supported on the Node.js version, isMainThread always returns true and threadId always returns 0, otherwise returns the appropriate value.

Provides a utility that can be used to determine if the current thread
is the main Node.js thread or a worker thread, even if worker threads
are not supported.
Copy link
Contributor

@goto-bus-stop goto-bus-stop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the support check, since we're only supporting 10.12+ now?

@jasnell
Copy link
Contributor Author

jasnell commented Apr 2, 2020

I'd actually forgotten that workers had been backported to 10.x :-)

As we spoke about on the phone, if we can make it such that clinic gracefully fails when run on an unsupported version, I think we can avoid adding this utility. Closing this PR with that assumption in mind. Keeping the branch tho in case we need to revisit.

@jasnell jasnell closed this Apr 2, 2020
@jasnell jasnell reopened this Apr 3, 2020
@jasnell
Copy link
Contributor Author

jasnell commented Apr 3, 2020

Actually, it appears this still may be necessary. worker_threads is behind a flag on 10.x (clinicjs/node-clinic-doctor#309 (comment))

Copy link
Contributor

@goto-bus-stop goto-bus-stop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in that case 👍

@jasnell jasnell changed the base branch from master to main August 21, 2020 18:47
@jasnell jasnell closed this Nov 24, 2020
@esmorodin
Copy link

Confirm, that fix from clinicjs/node-clinic-doctor/pull/309 works, because otherwise I faced this error: clinicjs/node-clinic#414.
Node version: bash-3.2$ node -v v18.12.0
FYI @jasnell

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.

3 participants