Détail du package

get-ready

node-modules934.6kMIT3.4.0

mixin to add one-time ready event callback handler

ready, get-ready, once, event

readme

get-ready

NPM version CI Test coverage npm download Node.js Version

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'));

ReadyEventEmitter

import { ReadyEventEmitter } from 'get-ready';

class MyClass extends ReadyEventEmitter {
  // your handler here
}

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

Contributors

Made with contributors-img.

changelog

Changelog

3.4.0 (2024-12-18)

Features

  • export hasReadyCallbacks getter (#7) (8b09b7c)

3.3.0 (2024-12-18)

Features

  • export isReady and readyError getter (#6) (cce2f08)

3.2.0 (2024-12-15)

Features

  • merge Ready and EventEmitter (#5) (bb049ea)

3.1.0 (2023-10-10)

Features

3.0.0 (2023-06-05)

⚠ BREAKING CHANGES

  • Drop Node.js < 16.13.0 support

https://github.com/eggjs/egg-core/issues/264

Features

2.0.1 / 2017-02-09

  • fix: it should reject error when ready return promise (#3)

2.0.0 / 2017-02-08

  • feat: [BREAKING_CHANGE] reimplement get-ready (#2)
  • fix typo on readme

1.0.0 / 2015-09-29

  • chore: use eslint and es6
  • test: add test with co
  • travis: test on node(1,2,3,4)
  • feat: support promise
  • fork from supershabam/ready