1 | import { AsyncIterableX } from './asynciterablex';
|
2 | import { sleep } from './_sleep';
|
3 | import { throwIfAborted } from '../aborterror';
|
4 | class IntervalAsyncIterable extends AsyncIterableX {
|
5 | constructor(dueTime) {
|
6 | super();
|
7 | this._dueTime = dueTime;
|
8 | }
|
9 | async *[Symbol.asyncIterator](signal) {
|
10 | throwIfAborted(signal);
|
11 | let i = 0;
|
12 | while (1) {
|
13 | await sleep(this._dueTime, signal);
|
14 | yield i++;
|
15 | }
|
16 | }
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | export function interval(dueTime) {
|
26 | return new IntervalAsyncIterable(dueTime);
|
27 | }
|
28 |
|
29 |
|