-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Update doc/api/worker_threads.md
- Loading branch information
Showing
9 changed files
with
50 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { isInternalThread } = require('node:worker_threads'); | ||
|
||
console.log(isInternalThread); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { isInternalThread, parentPort } = require('node:worker_threads'); | ||
|
||
parentPort.postMessage(isInternalThread); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { spawnPromisified } from '../common/index.mjs'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import assert from 'node:assert'; | ||
import { execPath } from 'node:process'; | ||
import { describe, it } from 'node:test'; | ||
import { isInternalThread, Worker } from 'node:worker_threads'; | ||
import * as common from '../common/index.mjs'; | ||
|
||
describe('isInternalThread is only true on InternalWorker', { concurrency: !process.env.TEST_PARALLEL }, () => { | ||
it('should be true inside the loader thread', async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ | ||
'--no-warnings', | ||
'--experimental-loader', | ||
fixtures.fileURL('loader-is-internal-thread.js'), | ||
'--eval', | ||
'setTimeout(() => {},99)', | ||
]); | ||
|
||
assert.strictEqual(stderr, ''); | ||
assert.match(stdout, /^true\r?\n$/); | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
}); | ||
|
||
it('should be false inside the main thread', async () => { | ||
assert.ok(!isInternalThread); | ||
}); | ||
|
||
it('should be false inside a regular worker thread', async () => { | ||
const worker = new Worker(fixtures.path('worker-is-internal-thread.js')); | ||
|
||
worker.on('message', common.mustCall((isInternalThread) => { | ||
assert.ok(!isInternalThread); | ||
})); | ||
}); | ||
}); |