tream
Version:
Lightweight lazy streams in TypeScript
24 lines • 694 B
JavaScript
import { none, taken } from './stream';
var now = Date.now ? function () { return Date.now(); } :
function () { return new Date().getTime(); };
export function interval(period) {
var time = now();
var pull_ = function (push) {
var pre_ = time;
time = now();
var timer = setTimeout(function () {
time = now();
push(none, pull_);
}, Math.max(0, period - (time - pre_)));
return function () {
clearTimeout(timer);
time = pre_;
return pull_;
};
};
return pull_;
}
export function timeout(delay) {
return taken(1, interval(delay));
}
//# sourceMappingURL=timer.js.map