File tree Expand file tree Collapse file tree
lib/internal/streams/iter Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1316,7 +1316,8 @@ added: v24.20.0
13161316
13171317* `input` {AsyncIterable|Iterable|BroadcastChannel}
13181318* `options` {Object} Same as `broadcast()`.
1319- * Returns: {Object} `{ writer, broadcast }`
1319+ * Returns: {BroadcastChannel|Object} A `broadcastProtocol` input returns its
1320+ {BroadcastChannel} directly. Other inputs return `{ writer, broadcast }`.
13201321
13211322Create a {BroadcastChannel} from an existing source. The source is consumed
13221323automatically and pushed to all subscribers.
@@ -1801,7 +1802,7 @@ class MessageBus {
18011802}
18021803
18031804const bus = new MessageBus();
1804- const { broadcast } = Broadcast.from(bus);
1805+ const broadcast = Broadcast.from(bus);
18051806const consumer = broadcast.push();
18061807bus.send('hello');
18071808bus.close();
@@ -1837,7 +1838,7 @@ class MessageBus {
18371838}
18381839
18391840const bus = new MessageBus();
1840- const { broadcast } = Broadcast.from(bus);
1841+ const broadcast = Broadcast.from(bus);
18411842const consumer = broadcast.push();
18421843bus.send('hello');
18431844bus.close();
Original file line number Diff line number Diff line change @@ -934,7 +934,7 @@ const Broadcast = {
934934 throw new ERR_INVALID_RETURN_VALUE(
935935 'an object', '[Symbol.for(\'Stream.broadcastProtocol\')]', bc);
936936 }
937- return { __proto__: null, writer: { __proto__: null }, broadcast: bc } ;
937+ return bc ;
938938 }
939939
940940 const source = from(input);
Original file line number Diff line number Diff line change @@ -181,6 +181,15 @@ async function testBroadcastFromSourceError() {
181181// Protocol validation
182182// =============================================================================
183183
184+ function testBroadcastProtocolReturnsBroadcast() {
185+ const { broadcast: expected } = broadcast();
186+ const obj = {
187+ [Symbol.for('Stream.broadcastProtocol')]() { return expected; },
188+ };
189+ assert.strictEqual(Broadcast.from(obj), expected);
190+ expected.cancel();
191+ }
192+
184193function testBroadcastProtocolReturnsNull() {
185194 const obj = {
186195 [Symbol.for('Stream.broadcastProtocol')]() { return null; },
@@ -223,6 +232,7 @@ Promise.all([
223232 testAlreadyAbortedSignal(),
224233 testBroadcastFromCancelWhileBlocked(),
225234 testBroadcastFromSourceError(),
235+ testBroadcastProtocolReturnsBroadcast(),
226236 testBroadcastProtocolReturnsNull(),
227237 testBroadcastProtocolReturnsString(),
228238 testBroadcastProtocolReturnsUndefined(),
You can’t perform that action at this time.
0 commit comments