Created
September 26, 2013 16:00
-
-
Save ben-bradley/6716254 to your computer and use it in GitHub Desktop.
A copy of the Guvna to stick into bradleyit.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Guvna(options) { | |
// error checking | |
if (!options.list || !options.callback || !options.done) { | |
console.log('ERROR: missing required option - { list: [], callback: fn(), done: fn() }'); | |
return false; | |
} | |
// assign vars | |
this.list = options.list; | |
this.callback = options.callback; | |
this.done = options.done; | |
// assign counters | |
this.max = (options.max && options.max < options.list.length) ? options.max : options.list.length; | |
this.started = 0; | |
this.completed = 0; | |
} | |
Guvna.prototype = { | |
start: function() { while (this.started < this.max) { this.callback(this.list[this.started++]); } }, | |
next: function() { | |
this.completed += 1; | |
if (this.list[this.started]) { this.callback(this.list[this.started++]); } | |
else if (this.completed == this.list.length) { this.done(); } | |
} | |
}; | |
module.exports = Guvna; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment