UNPKG

910 BJavaScriptView Raw
1import { AsyncIterableX } from './asynciterablex';
2export class RepeatAsyncIterable extends AsyncIterableX {
3 constructor(source, count) {
4 super();
5 this._source = source;
6 this._count = count;
7 }
8 async *[Symbol.asyncIterator]() {
9 if (this._count === -1) {
10 while (1) {
11 for await (let item of this._source) {
12 yield item;
13 }
14 }
15 }
16 else {
17 for (let i = 0; i < this._count; i++) {
18 for await (let item of this._source) {
19 yield item;
20 }
21 }
22 }
23 }
24}
25export function repeat(source, count = -1) {
26 return new RepeatAsyncIterable(source, count);
27}
28export function repeatStatic(value, count = -1) {
29 return new RepeatAsyncIterable(AsyncIterableX.of(value), count);
30}
31
32//# sourceMappingURL=repeat.mjs.map