get-ready
mixin to add one-time ready event callback handler
Last updated 3 years ago by fengmk2 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install get-ready 
SYNC missed versions from official npm registry.

get-ready

NPM version CI Test coverage npm download

Fork from supershabam/ready

one-time ready event object.

Usage

Create ready event object.

import { Ready } from 'get-ready';

const obj = new Ready();

// register a callback
obj.ready(() => console.log('ready'));

// mark 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.

// already ready
obj.ready(true);
obj.ready().then(() => console.log('ready'));

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);
// call immediately
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


supershabam


fengmk2


popomore


dead-horse


semantic-release-bot

This project follows the git-contributor spec, auto updated at Mon Jun 05 2023 14:06:50 GMT+0800.

Current Tags

  • 3.1.0                                ...           latest (3 years ago)

5 Versions

  • 3.1.0                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.0.0                                ...           11 years ago
Downloads
Today 1
This Week 48
This Month 72
Last Day 6
Last Week 39
Last Month 206
Dependencies (0)
None
Dev Dependencies (10)

Copyright 2013 - present © cnpmjs.org | Home |