mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -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
85bd860703
commit
d72fb59ddc
4 files changed
+16
-6
No files matched your search
@@ -1374,7 +1374,8 @@ added:
|
||||
|
||||
* `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.
|
||||
@@ -1883,7 +1884,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();
|
||||
@@ -1919,7 +1920,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();
|
||||
|
||||
@@ -923,7 +923,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(),
|
||||
|
||||
@@ -140,8 +140,7 @@ async function testMultiConsumerProtocolsSnapshotMethods() {
|
||||
const broadcastTarget = broadcast().broadcast;
|
||||
const broadcastFixture = protocolFixture(
|
||||
broadcastProtocol, broadcastTarget);
|
||||
assert.strictEqual(
|
||||
Broadcast.from(broadcastFixture.input).broadcast, broadcastTarget);
|
||||
assert.strictEqual(Broadcast.from(broadcastFixture.input), broadcastTarget);
|
||||
assert.strictEqual(broadcastFixture.accesses, 1);
|
||||
|
||||
const shareTarget = share('abc');
|
||||
|
||||
Reference in new issue
Block a user