ready
NodeJS mixin to add one-time ready event
Purpose
Events are great. You should use events, but not for signaling ready! Ready implies state, and once you are ready, you stay ready.
This is a module for everyone who has bound an event handler.on('ready', function() {}) that doesn't execute because you added the handler after the 'ready' event already fired.
Warning
If you use this mixin, you must have 'ready', '_ready', and '_readyCallbacks' available on your class. Ready will stomp on these variables if you're trying to use them in your class.
Example
var ready = require('ready');
function MyClass() {
this.someProperty = 'some value';
}
ready.mixin(MyClass.prototype);
MyClass.prototype.doSomeWork = function() {};
var myClass = new MyClass();
myClass.ready(function() {
console.log('I am now ready');
});
myClass.doSomeWork();
myClass.ready(true);
myClass.ready(function() {
console.log('I came late to the party, but I will still execute.');
});
myClass.ready(false);
myClass.ready(function() {
console.log('I will not fire until you set ready to true again.');
});