MCPcopy Index your code
hub / github.com/graphql/graphql-js / mapAsyncIterable

Function mapAsyncIterable

src/execution/mapAsyncIterable.ts:12–33  ·  view source on GitHub ↗
(
  iterable: AsyncGenerator<T> | AsyncIterable<T>,
  callback: (value: T) => PromiseOrValue<U>,
)

Source from the content-addressed store, hash-verified

10 * @internal
11 */
12export function mapAsyncIterable<T, U>(
13 iterable: AsyncGenerator<T> | AsyncIterable<T>,
14 callback: (value: T) => PromiseOrValue<U>,
15): AsyncGenerator<U, void, void> {
16 const iterator = iterable[Symbol.asyncIterator]();
17 const returnFn = iterator.return?.bind(iterator);
18 const throwFn = iterator.throw?.bind(iterator);
19
20 const onReturn = returnFn
21 ? () => callIgnoringErrors(returnFn)
22 : () => Promise.resolve();
23
24 const onThrow = throwFn
25 ? (reason?: unknown) => callIgnoringErrors(() => throwFn(reason))
26 : onReturn;
27
28 return withConcurrentAbruptClose(
29 mapAsyncIterableImpl(iterable, callback),
30 onReturn,
31 onThrow,
32 );
33}
34
35async function callIgnoringErrors(fn: () => Promise<unknown>): Promise<void> {
36 try {

Callers 5

mapSourceToResponseEventFunction · 0.90
buildResponseMethod · 0.90
buildResponseMethod · 0.90

Calls 3

callIgnoringErrorsFunction · 0.85
mapAsyncIterableImplFunction · 0.85

Tested by 1