-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: allow URL in Worker constructor
The explicit goal is to let users use `import.meta.url` to re-load thecurrent module inside a Worker instance. Fixes: #30780 PR-URL: #31664 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
- Loading branch information
1 parent
597bcb5
commit e83dcde
Showing
8 changed files
with
104 additions
and
20 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import '../common/index.mjs'; | ||
import assert from 'assert'; | ||
import { Worker } from 'worker_threads'; | ||
|
||
const re = /The argument 'options\.eval' must be false when 'filename' is not a string\./; | ||
assert.throws(() => new Worker(new URL(import.meta.url), { eval: true }), re); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { mustCall } from '../common/index.mjs'; | ||
import assert from 'assert'; | ||
import { Worker, isMainThread, parentPort } from 'worker_threads'; | ||
|
||
const TEST_STRING = 'Hello, world!'; | ||
|
||
if (isMainThread) { | ||
const w = new Worker(new URL(import.meta.url)); | ||
w.on('message', mustCall((message) => { | ||
assert.strictEqual(message, TEST_STRING); | ||
})); | ||
} else { | ||
setImmediate(() => { | ||
process.nextTick(() => { | ||
parentPort.postMessage(TEST_STRING); | ||
}); | ||
}); | ||
} |