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

Function abortableNext

lib/internal/streams/iter/pull.js:703–721  ·  view source on GitHub ↗

* Read one item from an async iterator, rejecting early if the signal aborts. * @param {AsyncIterator} iterator - The iterator to read from. * @param {AbortSignal|undefined} signal - Optional abort signal. * @returns {Promise >|IteratorResult }

(iterator, signal)

Source from the content-addressed store, hash-verified

701 * @returns {Promise<IteratorResult<Uint8Array[]>>|IteratorResult<Uint8Array[]>}
702 */
703function abortableNext(iterator, signal) {
704 if (signal === undefined) {
705 return iterator.next();
706 }
707
708 signal.throwIfAborted();
709
710 const next = iterator.next();
711 const { promise, reject } = PromiseWithResolvers();
712 const onAbort = getOnAbort(reject, signal);
713 signal.addEventListener('abort', onAbort, { __proto__: null, once: true });
714 if (signal.aborted) {
715 onAbort();
716 }
717
718 return SafePromisePrototypeFinally(SafePromiseRace([next, promise]), () => {
719 signal.removeEventListener('abort', onAbort);
720 });
721}
722
723/**
724 * Wrap an async source so each pending read is abort-aware.

Callers 1

[SymbolAsyncIterator]Function · 0.85

Calls 6

getOnAbortFunction · 0.85
throwIfAbortedMethod · 0.80
onAbortFunction · 0.70
nextMethod · 0.65
addEventListenerMethod · 0.65
removeEventListenerMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…