get-ready
=====
Fork from supershabam/ready
NodeJS mixin to add one-time ready event
Usage
Using ready
or ready.mixin
to add ready
method to the given object.
const ready = ;const obj = {};ready; // register a callbackobj; // mark readyobj;
Register
Register a callback to the callback stack, it will be called when mark as ready, see example above.
If the callback is undefined, register will return a promise.
obj;obj;
If it has been ready, the callback will be called immediately.
// already readyobj;obj;
Warning: the callback is called after nextTick
Emit
Mark it as ready, you can simply using .ready(true)
.
You can also mark it not ready.
obj;// call immediatelyobj; obj;obj;
When exception throws, you can pass an error object, then the callback will receive it as the first argument.
obj;obj;