faye
Version:
Simple pub/sub messaging for the web
47 lines (33 loc) • 859 B
JavaScript
;
var assign = require('../util/assign');
var Scheduler = function(message, options) {
this.message = message;
this.options = options;
this.attempts = 0;
};
assign(Scheduler.prototype, {
getTimeout: function() {
return this.options.timeout;
},
getInterval: function() {
return this.options.interval;
},
isDeliverable: function() {
var attempts = this.options.attempts,
made = this.attempts,
deadline = this.options.deadline,
now = new Date().getTime();
if (attempts !== undefined && made >= attempts)
return false;
if (deadline !== undefined && now > deadline)
return false;
return true;
},
send: function() {
this.attempts += 1;
},
succeed: function() {},
fail: function() {},
abort: function() {}
});
module.exports = Scheduler;