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

Method next

lib/internal/webstreams/readablestream.js:559–603  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

557 // await uses here do not trigger that failure because
558 // the test that fails does not trigger those code paths.
559 next() {
560 // If this is the first read, delay by one microtask
561 // to ensure that the controller has had an opportunity
562 // to properly start and perform the initial pull.
563 // TODO(@jasnell): The spec doesn't call this out so
564 // need to investigate if it's a bug in our impl or
565 // the spec.
566 if (!started) {
567 state.current = PromiseResolve();
568 started = true;
569 }
570 if (state.current !== undefined) {
571 state.current =
572 PromisePrototypeThen(state.current, nextSteps, nextSteps);
573 return state.current;
574 }
575 // No read is in flight. Mirror the buffered fast path of
576 // ReadableStreamDefaultReader.read(): when data is already queued
577 // in a default controller, resolve immediately without allocating
578 // a read request. The result settles synchronously, so leaving
579 // state.current undefined matches the state the slow path reaches
580 // once its read request callbacks have settled.
581 const stream = reader[kState].stream;
582 if (!state.done && stream !== undefined) {
583 const controller = stream[kState].controller;
584 if (stream[kState].state === 'readable' &&
585 isReadableStreamDefaultController(controller) &&
586 controller[kState].queue.length > 0) {
587 stream[kState].disturbed = true;
588 const chunk = dequeueValue(controller);
589
590 if (controller[kState].closeRequested &&
591 !controller[kState].queue.length) {
592 readableStreamDefaultControllerClearAlgorithms(controller);
593 readableStreamClose(stream);
594 } else {
595 readableStreamDefaultControllerCallPullIfNeeded(controller);
596 }
597
598 return PromiseResolve({ done: false, value: chunk });
599 }
600 }
601 state.current = nextSteps();
602 return state.current;
603 },
604
605 return(error) {
606 started = true;

Callers

nothing calls this directly

Tested by

no test coverage detected