Skip to content

Instantly share code, notes, and snippets.

@rf
Created January 20, 2015 21:08
Show Gist options
  • Save rf/0ab32d087b1bdcd86b30 to your computer and use it in GitHub Desktop.
Save rf/0ab32d087b1bdcd86b30 to your computer and use it in GitHub Desktop.
module.exports = Ready
function Ready() {
var ready = false
var listeners = []
var args
onready.emit = onready
onready.ready = false
return onready
function onready(callback) {
if (typeof callback !== "function" && !ready) {
ready = true
onready.ready = true
args = arguments
listeners.forEach(call)
return (listeners = [])
} else if (ready) {
return callback && call(callback)
}
listeners.push(callback)
}
function call(cb) {
cb.apply(null, args)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment