UNPKG

tream

Version:

Lightweight lazy streams in TypeScript

28 lines 827 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var stream_1 = require("./stream"); var now = Date.now ? function () { return Date.now(); } : function () { return new Date().getTime(); }; function interval(period) { var time = now(); var pull_ = function (push) { var pre_ = time; time = now(); var timer = setTimeout(function () { time = now(); push(stream_1.none, pull_); }, Math.max(0, period - (time - pre_))); return function () { clearTimeout(timer); time = pre_; return pull_; }; }; return pull_; } exports.interval = interval; function timeout(delay) { return stream_1.taken(1, interval(delay)); } exports.timeout = timeout; //# sourceMappingURL=timer.js.map