MCPcopy Index your code
hub / github.com/nodejs/node / getNext

Method getNext

lib/internal/streams/iter/share.js:133–187  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

131 __proto__: null,
132 [SymbolAsyncIterator]() {
133 const getNext = async () => {
134 if (self.#sourceError) {
135 state.detached = true;
136 self.#consumers.delete(state);
137 throw self.#sourceError;
138 }
139
140 // Loop until we get data, source is exhausted, or
141 // consumer is detached. Multiple consumers may be woken
142 // after a single pull - those that find no data at their
143 // cursor must re-pull rather than terminating prematurely.
144 for (;;) {
145 if (state.detached) {
146 if (self.#sourceError) throw self.#sourceError;
147 return { __proto__: null, done: true, value: undefined };
148 }
149
150 if (self.#cancelled) {
151 state.detached = true;
152 self.#deleteConsumer(state);
153 return { __proto__: null, done: true, value: undefined };
154 }
155
156 // Check if data is available in buffer
157 const bufferIndex = state.cursor - self.#bufferStart;
158 if (bufferIndex < self.#buffer.length) {
159 const chunk = self.#buffer.get(bufferIndex);
160 const cursor = state.cursor;
161 state.cursor++;
162 if (cursor === self.#cachedMinCursor &&
163 --self.#cachedMinCursorConsumers === 0) {
164 self.#tryTrimBuffer();
165 }
166 return { __proto__: null, done: false, value: chunk };
167 }
168
169 if (self.#sourceExhausted) {
170 state.detached = true;
171 self.#deleteConsumer(state);
172 if (self.#sourceError) throw self.#sourceError;
173 return { __proto__: null, done: true, value: undefined };
174 }
175
176 // Need to pull from source - check buffer limit
177 const canPull = await self.#waitForBufferSpace();
178 if (!canPull) {
179 state.detached = true;
180 self.#deleteConsumer(state);
181 if (self.#sourceError) throw self.#sourceError;
182 return { __proto__: null, done: true, value: undefined };
183 }
184
185 await self.#pullFromSource();
186 }
187 };
188
189 return {
190 __proto__: null,

Callers

nothing calls this directly

Calls 6

#waitForBufferSpaceMethod · 0.80
deleteMethod · 0.65
getMethod · 0.65
#deleteConsumerMethod · 0.45
#tryTrimBufferMethod · 0.45
#pullFromSourceMethod · 0.45

Tested by

no test coverage detected