From 3d1cd02f27518f1a04374c7c8320cd5d82ede6e9 Mon Sep 17 00:00:00 2001 From: Minteck Date: Thu, 23 Feb 2023 19:34:56 +0100 Subject: Updated 40 files, added 37 files, deleted 1103 files and renamed 3905 files (automated) --- .../graphql/subscription/mapAsyncIterator.js.flow | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 includes/external/school/node_modules/graphql/subscription/mapAsyncIterator.js.flow (limited to 'includes/external/school/node_modules/graphql/subscription/mapAsyncIterator.js.flow') diff --git a/includes/external/school/node_modules/graphql/subscription/mapAsyncIterator.js.flow b/includes/external/school/node_modules/graphql/subscription/mapAsyncIterator.js.flow new file mode 100644 index 0000000..8b1d1d8 --- /dev/null +++ b/includes/external/school/node_modules/graphql/subscription/mapAsyncIterator.js.flow @@ -0,0 +1,74 @@ +// @flow strict +import { SYMBOL_ASYNC_ITERATOR } from '../polyfills/symbols'; + +import type { PromiseOrValue } from '../jsutils/PromiseOrValue'; + +/** + * Given an AsyncIterable and a callback function, return an AsyncIterator + * which produces values mapped via calling the callback function. + */ +export default function mapAsyncIterator( + iterable: AsyncIterable | AsyncGenerator, + callback: (T) => PromiseOrValue, + rejectCallback?: (any) => PromiseOrValue, +): AsyncGenerator { + // $FlowFixMe[prop-missing] + const iteratorMethod = iterable[SYMBOL_ASYNC_ITERATOR]; + const iterator: any = iteratorMethod.call(iterable); + let $return: any; + let abruptClose; + if (typeof iterator.return === 'function') { + $return = iterator.return; + abruptClose = (error: mixed) => { + const rethrow = () => Promise.reject(error); + return $return.call(iterator).then(rethrow, rethrow); + }; + } + + function mapResult(result: IteratorResult) { + return result.done + ? result + : asyncMapValue(result.value, callback).then(iteratorResult, abruptClose); + } + + let mapReject; + if (rejectCallback) { + // Capture rejectCallback to ensure it cannot be null. + const reject = rejectCallback; + mapReject = (error: mixed) => + asyncMapValue(error, reject).then(iteratorResult, abruptClose); + } + + /* TODO: Flow doesn't support symbols as keys: + https://github.com/facebook/flow/issues/3258 */ + return ({ + next(): Promise> { + return iterator.next().then(mapResult, mapReject); + }, + return() { + return $return + ? $return.call(iterator).then(mapResult, mapReject) + : Promise.resolve({ value: undefined, done: true }); + }, + throw(error?: mixed): Promise> { + if (typeof iterator.throw === 'function') { + return iterator.throw(error).then(mapResult, mapReject); + } + return Promise.reject(error).catch(abruptClose); + }, + [SYMBOL_ASYNC_ITERATOR]() { + return this; + }, + }: $FlowFixMe); +} + +function asyncMapValue( + value: T, + callback: (T) => PromiseOrValue, +): Promise { + return new Promise((resolve) => resolve(callback(value))); +} + +function iteratorResult(value: T): IteratorResult { + return { value, done: false }; +} -- cgit