# get-ready

> mixin to add one-time ready event callback handler

Latest version **3.4.0** (published 2024-12-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install get-ready
pnpm add get-ready
yarn add get-ready
bun add get-ready
```

## Health

**Score 45/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.4.0 |
| Published | 2024-12-18 |
| First published | 2015-09-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 16.13.0 |
| Dependencies | 0 |
| Unpacked size | 23.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | fengmk2 |
| Maintainers | gxkl, eggjs-admin, fengmk2, atian25, dead_horse, wanghx, hyj1991, killagu, coolme200, mansonchor.zzw, hubcarl, gemwuu, akitasummer, popomore |
| Keywords | ready, get-ready, once, event |

## Links

- npm: https://www.npmjs.com/package/get-ready
- Repository: https://github.com/node-modules/get-ready
- Homepage: https://github.com/node-modules/get-ready#readme
- Issues: https://github.com/node-modules/get-ready/issues
- npm.io page: https://npm.io/package/get-ready

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 3.4.0 (latest) — 2024-12-18
- 3.3.0 — 2024-12-18
- 3.2.0 — 2024-12-15
- 3.1.0 — 2023-10-10
- 3.0.0 — 2023-06-05
- 2.0.1 — 2017-02-09
- 2.0.0 — 2017-02-08
- 1.0.0 — 2015-09-29

## README

# get-ready

[![NPM version][npm-image]][npm-url]
[![CI](https://github.com/node-modules/get-ready/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/get-ready/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/get-ready.svg?style=flat)](https://nodejs.org/en/download/)

[npm-image]: https://img.shields.io/npm/v/get-ready.svg?style=flat-square
[npm-url]: https://npmjs.org/package/get-ready
[codecov-image]: https://codecov.io/github/node-modules/get-ready/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/node-modules/get-ready?branch=master
[download-image]: https://img.shields.io/npm/dm/get-ready.svg?style=flat-square
[download-url]: https://npmjs.org/package/get-ready

**Fork from [supershabam/ready](https://github.com/supershabam/ready)**

one-time ready event object.

## Usage

Create `ready` event object.

```ts
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.

```ts
obj.ready().then(() => console.log('ready'));
obj.ready(true);
```

If it has been ready, the callback will be called immediately.

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

### ReadyEventEmitter

```ts
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.

```ts
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.

```ts
obj.ready(err => console.log(err));
obj.ready(new Error('err'));
```

## License

[MIT](LICENSE)

## Contributors

[![Contributors](https://contrib.rocks/image?repo=node-modules/get-ready)](https://github.com/node-modules/get-ready/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).

---
_Source: https://npm.io/package/get-ready · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
