UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

30 lines (28 loc) 884 B
import { AsyncIterableX } from './asynciterablex.js'; import { sleep } from './_sleep.js'; import { throwIfAborted } from '../aborterror.js'; class IntervalAsyncIterable extends AsyncIterableX { _dueTime; constructor(dueTime) { super(); this._dueTime = dueTime; } async *[Symbol.asyncIterator](signal) { throwIfAborted(signal); let i = 0; while (1) { await sleep(this._dueTime, signal); yield i++; } } } /** * Produces a new item in an async-iterable at the given interval cycle time. * * @param {number} dueTime The due time in milliseconds to spawn a new item. * @returns {AsyncIterableX<number>} An async-iterable producing values at the specified interval. */ export function interval(dueTime) { return new IntervalAsyncIterable(dueTime); } //# sourceMappingURL=interval.js.map