MCPcopy Create free account
hub / github.com/nodejs/node / BroadcastImpl

Class BroadcastImpl

lib/internal/streams/iter/broadcast.js:85–474  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83// =============================================================================
84
85class BroadcastImpl {
86 #buffer = new RingBuffer();
87 #bufferStart = 0;
88 #consumers = new SafeSet();
89 #waiters = []; // Consumers with pending resolve (subset of #consumers)
90 #ended = false;
91 #error = null;
92 #cancelled = false;
93 #options;
94 #writer = null;
95 #cachedMinCursor = 0;
96 #cachedMinCursorConsumers = 0;
97
98 constructor(options) {
99 this.#options = options;
100 this[kOnBufferDrained] = null;
101 }
102
103 setWriter(writer) {
104 this.#writer = writer;
105 }
106
107 get backpressurePolicy() {
108 return this.#options.backpressure;
109 }
110
111 get highWaterMark() {
112 return this.#options.highWaterMark;
113 }
114
115 get consumerCount() {
116 return this.#consumers.size;
117 }
118
119 get bufferSize() {
120 return this.#buffer.length;
121 }
122
123 push(...args) {
124 const { transforms, options } = parsePullArgs(args);
125 const rawConsumer = this.#createRawConsumer();
126
127 // When transforms are present, delegate to pull() which creates its
128 // own internal AbortController that follows the external signal.
129 // When no transforms, return rawConsumer directly (controller elided
130 // per PULL-02 optimization -- no transforms means no signal recipient).
131 if (transforms.length > 0) {
132 const pullArgs = [...transforms];
133 if (options?.signal) {
134 ArrayPrototypePush(pullArgs,
135 { __proto__: null, signal: options.signal });
136 }
137 return pullWithTransforms(rawConsumer, ...pullArgs);
138 }
139 return rawConsumer;
140 }
141
142 #createRawConsumer() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected