Skip to content

Instantly share code, notes, and snippets.

@brapse
Created November 8, 2010 19:25
Show Gist options
  • Save brapse/668128 to your computer and use it in GitHub Desktop.
Save brapse/668128 to your computer and use it in GitHub Desktop.
Sequence
var Sequence = function (delay) {
EventEmitter.apply(this);
this.minDelay = 1000;
this.maxDelay = 3000;
this.delay = delay;
this.delayInterval = 10; // 10th of a second
}
sys.inherits(Sequence, EventEmitter);
Sequence.prototype.start = function () {
var that = this;
this.on('clockTick', function () {
setTimeout(function () {
that.emit('tick');
that.emit('clockTick');
}, that.delay);
});
this.emit('clockTick');
}
Sequence.prototype.incrementDelay = function () {
if (this.delay < this.maxDelay) {
this.delay += this.delayInterval;
}
}
Sequence.prototype.decrementDelay = function () {
if (this.delay > this.minDelay) {
this.delay -= this.delayInterval;
}
}
Sequence.prototype.stop = function () {
this.removeAllListeners('clockTick');
}
exports.Sequence = Sequence;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment