Created
January 20, 2015 21:08
-
-
Save rf/0ab32d087b1bdcd86b30 to your computer and use it in GitHub Desktop.
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
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