forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: make transfer list behave like web MessagePort
Allow generic iterables as transfer list arguments, as well as an options object with a `transfer` option, for web compatibility. Refs: nodejs#28033 (comment)
- Loading branch information
Showing
5 changed files
with
238 additions
and
77 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
26 changes: 26 additions & 0 deletions
26
test/parallel/test-worker-message-port-terminate-transfer-list.js
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,26 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
const { parentPort, MessageChannel, Worker } = require('worker_threads'); | ||
|
||
// Do not use isMainThread so that this test itself can be run inside a Worker. | ||
if (!process.env.HAS_STARTED_WORKER) { | ||
process.env.HAS_STARTED_WORKER = 1; | ||
const w = new Worker(__filename); | ||
w.once('message', common.mustCall(() => { | ||
w.once('message', common.mustNotCall()); | ||
setTimeout(() => w.terminate(), 100); | ||
})); | ||
} else { | ||
const { port1 } = new MessageChannel(); | ||
|
||
parentPort.postMessage('ready'); | ||
|
||
// Make sure we don’t end up running JS after the infinite loop is broken. | ||
port1.postMessage({}, { | ||
transfer: (function*() { while (true); })() | ||
}); | ||
|
||
parentPort.postMessage('UNREACHABLE'); | ||
process.kill(process.pid, 'SIGINT'); | ||
} |
Oops, something went wrong.