-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: make diagnostics_channel async iterable
- Loading branch information
Showing
2 changed files
with
104 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const dc = require('diagnostics_channel'); | ||
const assert = require('assert'); | ||
|
||
const input = { | ||
foo: 'bar' | ||
}; | ||
|
||
const channel = dc.channel('test'); | ||
|
||
const done = common.mustCall(); | ||
|
||
async function main() { | ||
for await (const message of channel) { | ||
assert.strictEqual(channel.hasSubscribers, true); | ||
assert.strictEqual(message, input); | ||
break; | ||
} | ||
|
||
// Make sure the subscription is cleaned up when breaking the loop! | ||
assert.strictEqual(channel.hasSubscribers, false); | ||
done(); | ||
} | ||
|
||
main(); | ||
|
||
setTimeout(common.mustCall(() => { | ||
channel.publish(input); | ||
}), 1); |