UNPKG

2.18 kBSource Map (JSON)View Raw
1{"version":3,"sources":["asynciterable/repeatvalue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,OAAO,wBAAkC,SAAQ,cAAuB;IAI5E,YAAY,KAAc,EAAE,KAAa;QACvC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAoB;QAChD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE;YACtB,OAAO,CAAC,EAAE;gBACR,cAAc,CAAC,MAAM,CAAC,CAAC;gBACvB,MAAM,IAAI,CAAC,MAAM,CAAC;aACnB;SACF;aAAM;YACL,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACpC,cAAc,CAAC,MAAM,CAAC,CAAC;gBACvB,MAAM,IAAI,CAAC,MAAM,CAAC;aACnB;SACF;IACH,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAU,KAAc,EAAE,QAAgB,CAAC,CAAC;IACrE,OAAO,IAAI,wBAAwB,CAAU,KAAK,EAAE,KAAK,CAAC,CAAC;AAC7D,CAAC","file":"repeatvalue.js","sourcesContent":["import { AsyncIterableX } from './asynciterablex';\nimport { throwIfAborted } from '../aborterror';\n\nexport class RepeatValueAsyncIterable<TSource> extends AsyncIterableX<TSource> {\n private _value: TSource;\n private _count: number;\n\n constructor(value: TSource, count: number) {\n super();\n this._value = value;\n this._count = count;\n }\n\n async *[Symbol.asyncIterator](signal?: AbortSignal) {\n if (this._count === -1) {\n while (1) {\n throwIfAborted(signal);\n yield this._value;\n }\n } else {\n for (let i = 0; i < this._count; i++) {\n throwIfAborted(signal);\n yield this._value;\n }\n }\n }\n}\n\n/**\n * Repeats a given value for the specified number of times as an async-iterable.\n *\n * @export\n * @template TSource The type of element to repeat.\n * @param {TSource} value The value to repeat as an async-iterable.\n * @param {number} [count=-1] The number of times to repeat the value, infinite if not specified.\n * @returns {AsyncIterableX<TSource>} An async-iterable with a single item that is repeated over the specified times.\n */\nexport function repeatValue<TSource>(value: TSource, count: number = -1): AsyncIterableX<TSource> {\n return new RepeatValueAsyncIterable<TSource>(value, count);\n}\n"]}
\No newline at end of file