UNPKG

ix

Version:

The Interactive Extensions for JavaScript

32 lines (30 loc) 1.04 kB
import { __asyncGenerator, __await } from "tslib"; import { AsyncIterableX } from './asynciterablex.mjs'; import { sleep } from './_sleep.mjs'; import { throwIfAborted } from '../aborterror.mjs'; class IntervalAsyncIterable extends AsyncIterableX { constructor(dueTime) { super(); this._dueTime = dueTime; } [Symbol.asyncIterator](signal) { return __asyncGenerator(this, arguments, function* _a() { throwIfAborted(signal); let i = 0; while (1) { yield __await(sleep(this._dueTime, signal)); yield yield __await(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.mjs.map