@johngw/stream
Version:
Reactive programming tools using the WHATWG Streams API.
30 lines • 707 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.interval = void 0;
/**
* Continuously emits `Date` chunks until cancelled.
*
* @group Sources
* @example
* ```
* interval(1_000)
*
* ------<Date>------<Date>------
* ```
*/
function interval(ms, queuingStrategy) {
let timer;
return new ReadableStream({
start(controller) {
timer = setInterval(() => {
if (controller.desiredSize)
controller.enqueue(new Date());
}, ms);
},
cancel() {
clearInterval(timer);
},
}, queuingStrategy);
}
exports.interval = interval;
//# sourceMappingURL=interval.js.map