mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
stream: make Broadcast.from() only return the Broadcast
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode PR-URL: https://github.com/nodejs/node/pull/66030 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
1 parent
4179233307
commit
39d1a5efd3
3 files changed
+15
-4
No files matched your search
@@ -1316,7 +1316,8 @@ added: v24.20.0
|
||||
|
||||
* `input` {AsyncIterable|Iterable|BroadcastChannel}
|
||||
* `options` {Object} Same as `broadcast()`.
|
||||
* Returns: {Object} `{ writer, broadcast }`
|
||||
* Returns: {BroadcastChannel|Object} A `broadcastProtocol` input returns its
|
||||
{BroadcastChannel} directly. Other inputs return `{ writer, broadcast }`.
|
||||
|
||||
Create a {BroadcastChannel} from an existing source. The source is consumed
|
||||
automatically and pushed to all subscribers.
|
||||
@@ -1801,7 +1802,7 @@ class MessageBus {
|
||||
}
|
||||
|
||||
const bus = new MessageBus();
|
||||
const { broadcast } = Broadcast.from(bus);
|
||||
const broadcast = Broadcast.from(bus);
|
||||
const consumer = broadcast.push();
|
||||
bus.send('hello');
|
||||
bus.close();
|
||||
@@ -1837,7 +1838,7 @@ class MessageBus {
|
||||
}
|
||||
|
||||
const bus = new MessageBus();
|
||||
const { broadcast } = Broadcast.from(bus);
|
||||
const broadcast = Broadcast.from(bus);
|
||||
const consumer = broadcast.push();
|
||||
bus.send('hello');
|
||||
bus.close();
|
||||
|
||||
@@ -934,7 +934,7 @@ const Broadcast = {
|
||||
throw new ERR_INVALID_RETURN_VALUE(
|
||||
'an object', '[Symbol.for(\'Stream.broadcastProtocol\')]', bc);
|
||||
}
|
||||
return { __proto__: null, writer: { __proto__: null }, broadcast: bc };
|
||||
return bc;
|
||||
}
|
||||
|
||||
const source = from(input);
|
||||
|
||||
@@ -181,6 +181,15 @@ async function testBroadcastFromSourceError() {
|
||||
// Protocol validation
|
||||
// =============================================================================
|
||||
|
||||
function testBroadcastProtocolReturnsBroadcast() {
|
||||
const { broadcast: expected } = broadcast();
|
||||
const obj = {
|
||||
[Symbol.for('Stream.broadcastProtocol')]() { return expected; },
|
||||
};
|
||||
assert.strictEqual(Broadcast.from(obj), expected);
|
||||
expected.cancel();
|
||||
}
|
||||
|
||||
function testBroadcastProtocolReturnsNull() {
|
||||
const obj = {
|
||||
[Symbol.for('Stream.broadcastProtocol')]() { return null; },
|
||||
@@ -223,6 +232,7 @@ Promise.all([
|
||||
testAlreadyAbortedSignal(),
|
||||
testBroadcastFromCancelWhileBlocked(),
|
||||
testBroadcastFromSourceError(),
|
||||
testBroadcastProtocolReturnsBroadcast(),
|
||||
testBroadcastProtocolReturnsNull(),
|
||||
testBroadcastProtocolReturnsString(),
|
||||
testBroadcastProtocolReturnsUndefined(),
|
||||
|
||||
Reference in new issue
Block a user