UNPKG

2.41 kBSource Map (JSON)View Raw
1{"version":3,"sources":["asynciterable/whiledo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,kBAA4B,SAAQ,cAAuB;IAI/D,YACE,SAA+D,EAC/D,MAA8B;QAE9B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAoB;QAChD,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;YACpC,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;gBAC5D,MAAM,IAAI,CAAC;aACZ;SACF;IACH,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,OAAO,CACrB,MAA8B,EAC9B,SAA+D;IAE/D,OAAO,IAAI,kBAAkB,CAAU,SAAS,EAAE,MAAM,CAAC,CAAC;AAC5D,CAAC","file":"whiledo.js","sourcesContent":["import { AsyncIterableX } from './asynciterablex';\nimport { wrapWithAbort } from './operators/withabort';\nimport { throwIfAborted } from '../aborterror';\n\nclass WhileAsyncIterable<TSource> extends AsyncIterableX<TSource> {\n private _condition: (signal?: AbortSignal) => boolean | Promise<boolean>;\n private _source: AsyncIterable<TSource>;\n\n constructor(\n condition: (signal?: AbortSignal) => boolean | Promise<boolean>,\n source: AsyncIterable<TSource>\n ) {\n super();\n this._condition = condition;\n this._source = source;\n }\n\n async *[Symbol.asyncIterator](signal?: AbortSignal) {\n throwIfAborted(signal);\n while (await this._condition(signal)) {\n for await (const item of wrapWithAbort(this._source, signal)) {\n yield item;\n }\n }\n }\n}\n\n/**\n * Repeats the given source as long as the specified conditions holds, where\n * the condition is evaluated before each repeated source is iterated.\n *\n * @export\n * @template TSource\n * @param {AsyncIterable<TSource>} source Source to repeat as long as the condition function evaluates to true.\n * @param {((signal?: AbortSignal) => boolean | Promise<boolean>)} condition Condition that will be evaluated before the source sequence is iterated.\n * @returns {AsyncIterableX<TSource>} An async-iterable which is repeated while the condition returns true.\n */\nexport function whileDo<TSource>(\n source: AsyncIterable<TSource>,\n condition: (signal?: AbortSignal) => boolean | Promise<boolean>\n): AsyncIterableX<TSource> {\n return new WhileAsyncIterable<TSource>(condition, source);\n}\n"]}
\No newline at end of file