get-ready

Fork from supershabam/ready
one-time ready event object.
Usage
Create ready
event object.
import { Ready } from 'get-ready';
const obj = new Ready();
obj.ready(() => console.log('ready'));
obj.ready(true);
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.ready().then(() => console.log('ready'));
obj.ready(true);
If it has been ready, the callback will be called immediately.
obj.ready(true);
obj.ready().then(() => console.log('ready'));
ReadyEventEmitter
import { ReadyEventEmitter } from 'get-ready';
class MyClass extends ReadyEventEmitter {
}
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.ready(true);
obj.ready(() => console.log('ready'));
obj.ready(false);
obj.ready(() => throw 'don\'t run');
When exception throws, you can pass an error object, then the callback will receive it as the first argument.
obj.ready(err => console.log(err));
obj.ready(new Error('err'));
License
MIT
Contributors

Made with contributors-img.