falcor
Version:
A JavaScript library for efficient data fetching.
33 lines (26 loc) • 742 B
JavaScript
function TimeoutScheduler(delay) {
this.delay = delay;
}
var TimerDisposable = function TimerDisposable(id) {
this.id = id;
this.disposed = false;
};
TimeoutScheduler.prototype.schedule = function schedule(action) {
var id = setTimeout(action, this.delay);
return new TimerDisposable(id);
};
TimeoutScheduler.prototype.scheduleWithState = function scheduleWithState(state, action) {
var self = this;
var id = setTimeout(function() {
action(self, state);
}, this.delay);
return new TimerDisposable(id);
};
TimerDisposable.prototype.dispose = function() {
if (this.disposed) {
return;
}
clearTimeout(this.id);
this.disposed = true;
};
module.exports = TimeoutScheduler;