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

Function yieldAbortable

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

* Wrap an async source so each pending read is abort-aware. * @param {AsyncIterable } source - The source to read from. * @param {AbortSignal|undefined} signal - Optional abort signal. * @returns {AsyncIterable }

(source, signal)

Source from the content-addressed store, hash-verified

727 * @returns {AsyncIterable<Uint8Array[]>}
728 */
729function yieldAbortable(source, signal) {
730 if (signal === undefined) {
731 return source;
732 }
733
734 return {
735 __proto__: null,
736 async *[SymbolAsyncIterator]() {
737 const iterator = source[SymbolAsyncIterator]();
738 let completed = false;
739 let aborted = false;
740
741 try {
742 while (true) {
743 const { done, value } = await abortableNext(iterator, signal);
744 if (done) {
745 completed = true;
746 return;
747 }
748 signal.throwIfAborted();
749 yield value;
750 }
751 } catch (error) {
752 aborted = signal.aborted;
753 throw error;
754 } finally {
755 if (!completed && typeof iterator.return === 'function') {
756 const result = iterator.return();
757 if (aborted) {
758 markPromiseAsHandled(result);
759 } else {
760 await result;
761 }
762 }
763 }
764 },
765 };
766}
767
768/**
769 * Create an async pipeline from source through transforms.

Callers 1

createAsyncPipelineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…