UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 2.73 kB
{"version":3,"sources":["asynciterable/operators/repeat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,OAAO,mBAA6B,SAAQ,cAAuB;IAIvE,YAAY,MAA8B,EAAE,KAAa;QACvD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAoB;QAChD,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE;YACtB,OAAO,CAAC,EAAE;gBACR,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;oBAC5D,MAAM,IAAI,CAAC;iBACZ;aACF;SACF;aAAM;YACL,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACpC,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;oBAC5D,MAAM,IAAI,CAAC;iBACZ;aACF;SACF;IACH,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAU,QAAgB,CAAC,CAAC;IAChD,OAAO,SAAS,sBAAsB,CAAC,MAA8B;QACnE,OAAO,IAAI,mBAAmB,CAAU,MAAM,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC,CAAC;AACJ,CAAC","file":"repeat.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { MonoTypeOperatorAsyncFunction } from '../../interfaces';\nimport { wrapWithAbort } from './withabort';\nimport { throwIfAborted } from '../../aborterror';\n\nexport class RepeatAsyncIterable<TSource> extends AsyncIterableX<TSource> {\n private _source: AsyncIterable<TSource>;\n private _count: number;\n\n constructor(source: AsyncIterable<TSource>, count: number) {\n super();\n this._source = source;\n this._count = count;\n }\n\n async *[Symbol.asyncIterator](signal?: AbortSignal) {\n throwIfAborted(signal);\n if (this._count === -1) {\n while (1) {\n for await (const item of wrapWithAbort(this._source, signal)) {\n yield item;\n }\n }\n } else {\n for (let i = 0; i < this._count; i++) {\n for await (const item of wrapWithAbort(this._source, signal)) {\n yield item;\n }\n }\n }\n }\n}\n\n/**\n * Repeats the async-enumerable sequence a specified number of times.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @param {number} [count=-1] Number of times to repeat the sequence. If not specified, the sequence repeats indefinitely.\n * @returns {MonoTypeOperatorAsyncFunction<TSource>} The async-iterable sequence producing the elements of the given sequence repeatedly.\n */\nexport function repeat<TSource>(count: number = -1): MonoTypeOperatorAsyncFunction<TSource> {\n return function repeatOperatorFunction(source: AsyncIterable<TSource>): AsyncIterableX<TSource> {\n return new RepeatAsyncIterable<TSource>(source, count);\n };\n}\n"]}