-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
worker: display MessagePort status in util.inspect() #22658
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
Changes from 4 commits
16f78ff
257228c
1556ba5
e394fb3
fb70a36
1db359c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
|
|
||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const util = require('util'); | ||
| const { MessageChannel } = require('worker_threads'); | ||
|
|
||
| const { port1, port2 } = new MessageChannel(); | ||
|
|
@@ -25,9 +26,22 @@ assert.throws(common.mustCall(() => { | |
| // The failed transfer should not affect the ports in anyway. | ||
| port2.onmessage = common.mustCall((message) => { | ||
| assert.strictEqual(message, 2); | ||
|
|
||
| assert(util.inspect(port1).includes('active: true'), util.inspect(port1)); | ||
| assert(util.inspect(port2).includes('active: true'), util.inspect(port2)); | ||
|
|
||
| port1.close(); | ||
|
|
||
| setTimeout(common.mustNotCall('The communication channel is still open'), | ||
| common.platformTimeout(1000)).unref(); | ||
| tick(10, () => { | ||
| assert(util.inspect(port1).includes('active: false'), util.inspect(port1)); | ||
| assert(util.inspect(port2).includes('active: false'), util.inspect(port2)); | ||
| }); | ||
| }); | ||
| port1.postMessage(2); | ||
|
|
||
| function tick(n, cb) { | ||
| if (--n > 0) | ||
|
||
| return setImmediate(() => tick(n - 1, cb)); | ||
|
||
| else | ||
| cb(); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: could you please put
thison a separate line as it's kind of confusing?Also, I'd suggest extracting second argument creation to a separate variable to make it easier to understand =). Though I'm fine with this too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (moving to a separate line)