UNPKG

ix

Version:

The Interactive Extensions for JavaScript

36 lines (34 loc) 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.interval = void 0; const tslib_1 = require("tslib"); const asynciterablex_js_1 = require("./asynciterablex.js"); const _sleep_js_1 = require("./_sleep.js"); const aborterror_js_1 = require("../aborterror.js"); class IntervalAsyncIterable extends asynciterablex_js_1.AsyncIterableX { constructor(dueTime) { super(); this._dueTime = dueTime; } [Symbol.asyncIterator](signal) { return tslib_1.__asyncGenerator(this, arguments, function* _a() { (0, aborterror_js_1.throwIfAborted)(signal); let i = 0; while (1) { yield tslib_1.__await((0, _sleep_js_1.sleep)(this._dueTime, signal)); yield yield tslib_1.__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. */ function interval(dueTime) { return new IntervalAsyncIterable(dueTime); } exports.interval = interval; //# sourceMappingURL=interval.js.map