forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbroadcast.js
More file actions
800 lines (698 loc) · 22.1 KB
/
Copy pathbroadcast.js
File metadata and controls
800 lines (698 loc) · 22.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
'use strict';
// New Streams API - Broadcast
//
// Push-model multi-consumer streaming. A single writer can push data to
// multiple consumers. Each consumer has an independent cursor into a
// shared buffer.
const {
ArrayIsArray,
ArrayPrototypePush,
MathMax,
PromisePrototypeThen,
PromiseReject,
PromiseResolve,
PromiseWithResolvers,
SafeSet,
Symbol,
SymbolAsyncDispose,
SymbolAsyncIterator,
SymbolDispose,
TypedArrayPrototypeGetByteLength,
} = primordials;
const { lazyDOMException } = require('internal/util');
const {
codes: {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_RETURN_VALUE,
ERR_INVALID_STATE,
},
} = require('internal/errors');
const {
validateAbortSignal,
validateInteger,
validateObject,
} = require('internal/validators');
const {
broadcastProtocol,
drainableProtocol,
} = require('internal/streams/iter/types');
const {
isAsyncIterable,
isSyncIterable,
} = require('internal/streams/iter/from');
const {
pull: pullWithTransforms,
} = require('internal/streams/iter/pull');
const {
kMultiConsumerDefaultHWM,
kResolvedPromise,
clampHWM,
convertChunks,
getMinCursor,
hasProtocol,
onSignalAbort,
parsePullArgs,
wrapError,
toUint8Array,
validateBackpressure,
} = require('internal/streams/iter/utils');
const {
RingBuffer,
} = require('internal/streams/iter/ringbuffer');
const kCancelWriter = Symbol('kCancelWriter');
const kWrite = Symbol('kWrite');
const kEnd = Symbol('kEnd');
const kAbort = Symbol('kAbort');
const kGetDesiredSize = Symbol('kGetDesiredSize');
const kCanWrite = Symbol('kCanWrite');
const kOnBufferDrained = Symbol('kOnBufferDrained');
// =============================================================================
// Broadcast Implementation
// =============================================================================
class BroadcastImpl {
#buffer = new RingBuffer();
#bufferStart = 0;
#consumers = new SafeSet();
#waiters = []; // Consumers with pending resolve (subset of #consumers)
#ended = false;
#error = null;
#cancelled = false;
#options;
#writer = null;
#cachedMinCursor = 0;
#cachedMinCursorConsumers = 0;
constructor(options) {
this.#options = options;
this[kOnBufferDrained] = null;
}
setWriter(writer) {
this.#writer = writer;
}
get backpressurePolicy() {
return this.#options.backpressure;
}
get highWaterMark() {
return this.#options.highWaterMark;
}
get consumerCount() {
return this.#consumers.size;
}
get bufferSize() {
return this.#buffer.length;
}
push(...args) {
const { transforms, options } = parsePullArgs(args);
const rawConsumer = this.#createRawConsumer();
// When transforms are present, delegate to pull() which creates its
// own internal AbortController that follows the external signal.
// When no transforms, return rawConsumer directly (controller elided
// per PULL-02 optimization -- no transforms means no signal recipient).
if (transforms.length > 0 || options?.signal) {
const pullArgs = [...transforms];
if (options?.signal) {
ArrayPrototypePush(pullArgs,
{ __proto__: null, signal: options.signal });
}
return pullWithTransforms(rawConsumer, ...pullArgs);
}
return rawConsumer;
}
#createRawConsumer() {
const state = {
__proto__: null,
// Start at the oldest buffered entry so late-joining consumers
// can read data already in the buffer.
cursor: this.#bufferStart,
resolve: null,
reject: null,
detached: false,
};
this.#consumers.add(state);
if (this.#consumers.size === 1) {
this.#cachedMinCursor = state.cursor;
this.#cachedMinCursorConsumers = 1;
} else if (state.cursor === this.#cachedMinCursor) {
this.#cachedMinCursorConsumers++;
} else {
this.#recomputeMinCursor();
}
const self = this;
const kDone = PromiseResolve(
{ __proto__: null, done: true, value: undefined });
function detach() {
state.detached = true;
state.resolve?.({ __proto__: null, done: true, value: undefined });
state.resolve = null;
state.reject = null;
if (self.#deleteConsumer(state)) {
self.#tryTrimBuffer();
}
}
return {
__proto__: null,
[SymbolAsyncIterator]() {
return {
__proto__: null,
next() {
if (state.detached) {
if (self.#error) return PromiseReject(self.#error);
return kDone;
}
const bufferIndex = state.cursor - self.#bufferStart;
if (bufferIndex < self.#buffer.length) {
const chunk = self.#buffer.get(bufferIndex);
const cursor = state.cursor;
state.cursor++;
if (cursor === self.#cachedMinCursor &&
--self.#cachedMinCursorConsumers === 0) {
self.#tryTrimBuffer();
}
return PromiseResolve(
{ __proto__: null, done: false, value: chunk });
}
if (self.#error) {
state.detached = true;
self.#deleteConsumer(state);
return PromiseReject(self.#error);
}
if (self.#ended || self.#cancelled) {
detach();
return kDone;
}
const { promise, resolve, reject } = PromiseWithResolvers();
state.resolve = resolve;
state.reject = reject;
ArrayPrototypePush(self.#waiters, state);
return promise;
},
return() {
detach();
return kDone;
},
throw() {
detach();
return kDone;
},
};
},
};
}
cancel(reason) {
if (this.#cancelled) return;
this.#cancelled = true;
this.#ended = true; // Prevents [kAbort]() from redundantly iterating consumers
if (reason !== undefined) {
this.#error = reason;
}
// Reject pending writes on the writer so the pump doesn't hang
this.#writer?.[kCancelWriter]();
for (const consumer of this.#consumers) {
if (consumer.resolve) {
if (reason !== undefined) {
consumer.reject?.(reason);
} else {
consumer.resolve({ __proto__: null, done: true, value: undefined });
}
consumer.resolve = null;
consumer.reject = null;
}
consumer.detached = true;
}
this.#consumers.clear();
this.#cachedMinCursorConsumers = 0;
}
[SymbolDispose]() {
this.cancel();
}
// Methods accessed by BroadcastWriter via symbol keys
[kWrite](chunk) {
if (this.#ended || this.#cancelled) return false;
if (this.#buffer.length >= this.#options.highWaterMark) {
switch (this.#options.backpressure) {
case 'strict':
case 'block':
return false;
case 'drop-oldest':
this.#buffer.shift();
this.#bufferStart++;
for (const consumer of this.#consumers) {
if (consumer.cursor < this.#bufferStart) {
this.#deleteConsumerFromMin(consumer);
consumer.cursor = this.#bufferStart;
}
}
this.#recomputeMinCursor();
break;
case 'drop-newest':
return true;
}
}
this.#buffer.push(chunk);
this.#notifyConsumers();
return true;
}
[kEnd]() {
if (this.#ended) return;
this.#ended = true;
for (const consumer of this.#consumers) {
if (consumer.resolve) {
const bufferIndex = consumer.cursor - this.#bufferStart;
if (bufferIndex < this.#buffer.length) {
const chunk = this.#buffer.get(bufferIndex);
const cursor = consumer.cursor;
consumer.cursor++;
if (cursor === this.#cachedMinCursor &&
--this.#cachedMinCursorConsumers === 0) {
this.#tryTrimBuffer();
}
consumer.resolve({ __proto__: null, done: false, value: chunk });
} else {
consumer.resolve({ __proto__: null, done: true, value: undefined });
}
consumer.resolve = null;
consumer.reject = null;
}
}
}
[kAbort](reason) {
if (this.#ended || this.#error) return;
this.#error = reason;
this.#ended = true;
// Notify all waiting consumers and detach them
for (const consumer of this.#consumers) {
if (consumer.reject) {
consumer.reject(reason);
consumer.resolve = null;
consumer.reject = null;
}
consumer.detached = true;
}
this.#consumers.clear();
this.#cachedMinCursorConsumers = 0;
}
[kGetDesiredSize]() {
if (this.#ended || this.#cancelled) return null;
return MathMax(0, this.#options.highWaterMark - this.#buffer.length);
}
[kCanWrite]() {
if (this.#ended || this.#cancelled) return false;
if ((this.#options.backpressure === 'strict' ||
this.#options.backpressure === 'block') &&
this.#buffer.length >= this.#options.highWaterMark) {
return false;
}
return true;
}
// Private methods
#recomputeMinCursor() {
const { minCursor, minCursorConsumers } = getMinCursor(
this.#consumers, this.#bufferStart + this.#buffer.length);
this.#cachedMinCursor = minCursor;
this.#cachedMinCursorConsumers = minCursorConsumers;
}
#tryTrimBuffer() {
if (this.#cachedMinCursorConsumers === 0) {
this.#recomputeMinCursor();
}
const trimCount = this.#cachedMinCursor - this.#bufferStart;
if (trimCount > 0) {
this.#buffer.trimFront(trimCount);
this.#bufferStart = this.#cachedMinCursor;
if (this[kOnBufferDrained] &&
this.#buffer.length < this.#options.highWaterMark) {
this[kOnBufferDrained]();
}
}
}
#notifyConsumers() {
const waiters = this.#waiters;
if (waiters.length === 0) return;
// Swap out the waiters list so consumers that re-wait during
// resolve don't get processed twice in this cycle.
this.#waiters = [];
for (let i = 0; i < waiters.length; i++) {
const consumer = waiters[i];
if (consumer.resolve) {
const bufferIndex = consumer.cursor - this.#bufferStart;
if (bufferIndex < this.#buffer.length) {
const chunk = this.#buffer.get(bufferIndex);
const cursor = consumer.cursor;
consumer.cursor++;
if (cursor === this.#cachedMinCursor &&
--this.#cachedMinCursorConsumers === 0) {
this.#tryTrimBuffer();
}
const resolve = consumer.resolve;
consumer.resolve = null;
consumer.reject = null;
resolve({ __proto__: null, done: false, value: chunk });
} else {
// Still waiting -- put back
ArrayPrototypePush(this.#waiters, consumer);
}
}
}
}
#deleteConsumerFromMin(consumer) {
if (consumer.cursor === this.#cachedMinCursor) {
this.#cachedMinCursorConsumers--;
return this.#cachedMinCursorConsumers === 0;
}
return false;
}
#deleteConsumer(consumer) {
if (this.#consumers.delete(consumer)) {
return this.#deleteConsumerFromMin(consumer);
}
return false;
}
}
// =============================================================================
// BroadcastWriter
// =============================================================================
let getBroadcastPendingWrites;
class BroadcastWriter {
#broadcast;
#totalBytes = 0;
#closed;
#aborted = false;
#pendingWrites = new RingBuffer();
#pendingDrains = [];
static {
// Used in wireBroadcastWriteSignal ensure the signal listener can be
// constructed without closing over the chunk data, which may be large.
getBroadcastPendingWrites = (obj) => obj.#pendingWrites;
}
constructor(broadcastImpl) {
this.#broadcast = broadcastImpl;
this.#broadcast[kOnBufferDrained] = () => {
this.#resolvePendingWrites();
this.#resolvePendingDrains(true);
};
}
// The drainable protocol works with Stream.ondrain to provide a notification
// when the writer can accept more data after being backpressured.
[drainableProtocol]() {
const desired = this.desiredSize;
if (desired === null) return null;
if (desired > 0) return PromiseResolve(true);
const { promise, resolve, reject } = PromiseWithResolvers();
ArrayPrototypePush(this.#pendingDrains, { __proto__: null, resolve, reject });
return promise;
}
#isClosed() {
return this.#closed !== undefined;
}
#isClosedOrAborted() {
return this.#isClosed() || this.#aborted;
}
get desiredSize() {
return this.#isClosedOrAborted() ? null : this.#broadcast[kGetDesiredSize]();
}
#canUseWriteFastPath(options) {
return !options?.signal && !this.#isClosed() && !this.#aborted &&
this.#broadcast[kCanWrite]();
}
write(chunk, options) {
// Fast path: no signal, writer open, buffer has space
if (this.#canUseWriteFastPath(options)) {
const converted = toUint8Array(chunk);
this.#broadcast[kWrite]([converted]);
this.#totalBytes += TypedArrayPrototypeGetByteLength(converted);
return kResolvedPromise;
}
return this.#writevSlow([chunk], options);
}
writev(chunks, options) {
if (!ArrayIsArray(chunks)) {
throw new ERR_INVALID_ARG_TYPE('chunks', 'Array', chunks);
}
// Fast path: no signal, writer open, buffer has space
if (this.#canUseWriteFastPath(options)) {
const converted = convertChunks(chunks);
this.#broadcast[kWrite](converted);
for (let i = 0; i < converted.length; i++) {
this.#totalBytes += TypedArrayPrototypeGetByteLength(converted[i]);
}
return kResolvedPromise;
}
return this.#writevSlow(chunks, options);
}
async #writevSlow(chunks, options) {
const signal = options?.signal;
// Check for pre-aborted
signal?.throwIfAborted();
if (this.#isClosedOrAborted()) {
throw new ERR_INVALID_STATE.TypeError('Writer is closed');
}
const converted = convertChunks(chunks);
if (this.#broadcast[kWrite](converted)) {
for (let i = 0; i < converted.length; i++) {
this.#totalBytes += TypedArrayPrototypeGetByteLength(converted[i]);
}
return;
}
const policy = this.#broadcast.backpressurePolicy;
const hwm = this.#broadcast.highWaterMark;
if (policy === 'strict') {
if (this.#pendingWrites.length >= hwm) {
throw new ERR_INVALID_STATE.TypeError(
'Backpressure violation: too many pending writes. ' +
'Await each write() call to respect backpressure.');
}
return this.#createPendingWrite(converted, signal);
}
// 'block' policy
return this.#createPendingWrite(converted, signal);
}
writeSync(chunk) {
if (this.#isClosedOrAborted()) return false;
if (!this.#broadcast[kCanWrite]()) return false;
const converted =
toUint8Array(chunk);
if (this.#broadcast[kWrite]([converted])) {
this.#totalBytes += TypedArrayPrototypeGetByteLength(converted);
return true;
}
return false;
}
writevSync(chunks) {
if (!ArrayIsArray(chunks)) {
throw new ERR_INVALID_ARG_TYPE('chunks', 'Array', chunks);
}
if (this.#isClosedOrAborted()) return false;
if (!this.#broadcast[kCanWrite]()) return false;
const converted = convertChunks(chunks);
if (this.#broadcast[kWrite](converted)) {
for (let i = 0; i < converted.length; i++) {
this.#totalBytes += TypedArrayPrototypeGetByteLength(converted[i]);
}
return true;
}
return false;
}
// end() is synchronous internally - signal accepted for interface compliance.
end(options) {
if (this.#isClosed()) return this.#closed;
this.#closed = PromiseResolve(this.#totalBytes);
this.#broadcast[kEnd]();
this.#resolvePendingDrains(false);
return this.#closed;
}
endSync() {
if (this.#closed) return this.#totalBytes;
this.#closed = PromiseResolve(this.#totalBytes);
this.#broadcast[kEnd]();
this.#resolvePendingDrains(false);
return this.#totalBytes;
}
fail(reason) {
if (this.#isClosedOrAborted()) return;
this.#aborted = true;
this.#closed = PromiseResolve(this.#totalBytes);
const error = reason ?? new ERR_INVALID_STATE.TypeError('Failed');
this.#rejectPendingWrites(error);
this.#rejectPendingDrains(error);
this.#broadcast[kAbort](error);
}
[SymbolAsyncDispose]() {
this.fail();
return PromiseResolve();
}
[SymbolDispose]() {
this.fail();
}
[kCancelWriter]() {
if (this.#isClosed()) return;
this.#closed = PromiseResolve(this.#totalBytes);
this.#rejectPendingWrites(
lazyDOMException('Broadcast cancelled', 'AbortError'));
this.#resolvePendingDrains(false);
}
/**
* Create a pending write promise, optionally racing against a signal.
* If the signal fires, the entry is removed from pendingWrites and the
* promise rejects. Signal listeners are cleaned up on normal resolution.
* @returns {Promise<void>}
*/
#createPendingWrite(chunk, signal) {
const { promise, resolve, reject } = PromiseWithResolvers();
const entry = { __proto__: null, chunk, resolve, reject };
this.#pendingWrites.push(entry);
if (signal) {
wireBroadcastWriteSignal(entry, signal, resolve, reject, this);
}
return promise;
}
#resolvePendingWrites() {
while (this.#pendingWrites.length > 0 && this.#broadcast[kCanWrite]()) {
const pending = this.#pendingWrites.shift();
if (this.#broadcast[kWrite](pending.chunk)) {
for (let i = 0; i < pending.chunk.length; i++) {
this.#totalBytes += TypedArrayPrototypeGetByteLength(pending.chunk[i]);
}
pending.resolve();
} else {
this.#pendingWrites.unshift(pending);
break;
}
}
}
#rejectPendingWrites(error) {
while (this.#pendingWrites.length > 0) {
this.#pendingWrites.shift().reject(error);
}
}
#resolvePendingDrains(canWrite) {
const drains = this.#pendingDrains;
this.#pendingDrains = [];
for (let i = 0; i < drains.length; i++) {
drains[i].resolve(canWrite);
}
}
#rejectPendingDrains(error) {
const drains = this.#pendingDrains;
this.#pendingDrains = [];
for (let i = 0; i < drains.length; i++) {
drains[i].reject(error);
}
}
}
function wireBroadcastWriteSignal(entry, signal, resolve, reject, self) {
const onAbort = () => {
const pendingWrites = getBroadcastPendingWrites(self);
const idx = pendingWrites.indexOf(entry);
if (idx !== -1) pendingWrites.removeAt(idx);
entry.chunk = null;
reject(signal.reason ?? lazyDOMException('Aborted', 'AbortError'));
};
entry.resolve = function() {
signal.removeEventListener('abort', onAbort);
entry.chunk = null;
resolve();
};
entry.reject = function(reason) {
signal.removeEventListener('abort', onAbort);
entry.chunk = null;
reject(reason);
};
signal.addEventListener('abort', onAbort, { __proto__: null, once: true });
}
function onBroadcastCancel(broadcastImpl, signal) {
onSignalAbort(signal, () => broadcastImpl.cancel(signal.reason));
}
// =============================================================================
// Public API
// =============================================================================
/**
* Create a broadcast channel for push-model multi-consumer streaming.
* @param {{ highWaterMark?: number, backpressure?: string, signal?: AbortSignal }} [options]
* @returns {{ writer: Writer, broadcast: Broadcast }}
*/
function broadcast(options = { __proto__: null }) {
validateObject(options, 'options');
const {
highWaterMark = kMultiConsumerDefaultHWM,
backpressure = 'strict',
signal,
} = options;
validateInteger(highWaterMark, 'options.highWaterMark');
validateBackpressure(backpressure);
if (signal !== undefined) {
validateAbortSignal(signal, 'options.signal');
}
const opts = {
__proto__: null,
highWaterMark: clampHWM(highWaterMark),
backpressure,
signal,
};
const broadcastImpl = new BroadcastImpl(opts);
const writer = new BroadcastWriter(broadcastImpl);
broadcastImpl.setWriter(writer);
if (signal) {
onBroadcastCancel(broadcastImpl, signal);
}
return { __proto__: null, writer, broadcast: broadcastImpl };
}
function isBroadcastable(value) {
return hasProtocol(value, broadcastProtocol);
}
const Broadcast = {
__proto__: null,
from(input, options) {
if (isBroadcastable(input)) {
const bc = input[broadcastProtocol](options);
if (bc === null || typeof bc !== 'object') {
throw new ERR_INVALID_RETURN_VALUE(
'an object', '[Symbol.for(\'Stream.broadcastProtocol\')]', bc);
}
return { __proto__: null, writer: { __proto__: null }, broadcast: bc };
}
if (!isAsyncIterable(input) && !isSyncIterable(input)) {
throw new ERR_INVALID_ARG_TYPE(
'input', ['Broadcastable', 'AsyncIterable', 'Iterable'], input);
}
const result = broadcast(options);
const signal = options?.signal;
const pump = async () => {
const w = result.writer;
try {
if (isAsyncIterable(input)) {
for await (const chunks of input) {
signal?.throwIfAborted();
if (ArrayIsArray(chunks)) {
if (!w.writevSync(chunks)) {
await w.writev(chunks, signal ? { signal } : undefined);
}
} else if (!w.writeSync(chunks)) {
await w.write(chunks, signal ? { signal } : undefined);
}
}
} else if (isSyncIterable(input)) {
for (const chunks of input) {
signal?.throwIfAborted();
if (ArrayIsArray(chunks)) {
if (!w.writevSync(chunks)) {
await w.writev(chunks, signal ? { signal } : undefined);
}
} else if (!w.writeSync(chunks)) {
await w.write(chunks, signal ? { signal } : undefined);
}
}
}
if (w.endSync() < 0) {
await w.end(signal ? { signal } : undefined);
}
} catch (error) {
w.fail(wrapError(error));
}
};
PromisePrototypeThen(pump(), undefined, () => {});
return result;
},
};
module.exports = {
Broadcast,
broadcast,
};