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

Method read

lib/internal/streams/iter/push.js:384–413  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

382 // ===========================================================================
383
384 async read() {
385 // If there's data in the buffer, return it immediately
386 if (this.#slots.length > 0) {
387 const result = this.#drain();
388 this.#resolvePendingWrites();
389 // After draining, check if writer was closing and buffer is now empty
390 if (this.#writerState === 'closing' && this.#slots.length === 0) {
391 this.endDrained();
392 }
393 return { __proto__: null, done: false, value: result };
394 }
395
396 // Buffer empty and writer closing = drain complete
397 if (this.#writerState === 'closing') {
398 this.endDrained();
399 return { __proto__: null, done: true, value: undefined };
400 }
401
402 if (this.#writerState === 'closed') {
403 return { __proto__: null, done: true, value: undefined };
404 }
405
406 if (this.#writerState === 'errored') {
407 throw this.#error;
408 }
409
410 const { promise, resolve, reject } = PromiseWithResolvers();
411 this.#pendingReads.push({ __proto__: null, resolve, reject });
412 return promise;
413 }
414
415 consumerReturn() {
416 if (this.#consumerState !== 'active') return;

Callers 9

maybeReadMore_Function · 0.45
nReadingNextTickFunction · 0.45
resume_Function · 0.45
flowFunction · 0.45
createAsyncIteratorFunction · 0.45
compose.jsFile · 0.45
_duplexifyFunction · 0.45
nextFunction · 0.45

Calls 4

#drainMethod · 0.95
#resolvePendingWritesMethod · 0.95
endDrainedMethod · 0.95
pushMethod · 0.45

Tested by

no test coverage detected