# wait-and-go

> Tiny util to create cached + "wait-on" callbacks

Latest version **0.3.0** (published 2018-11-07) · 0 weekly downloads

## Install

```sh
npm install wait-and-go
pnpm add wait-and-go
yarn add wait-and-go
bun add wait-and-go
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2018-11-07 |
| First published | 2018-11-02 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Anton Kosykh |
| Maintainers | kelin2025 |
| Keywords | promise, delay, wait |

## Links

- npm: https://www.npmjs.com/package/wait-and-go
- Repository: https://github.com/kelin2025/wait-and-go
- npm.io page: https://npm.io/package/wait-and-go

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.3.0 (latest) — 2018-11-07
- 0.2.0 — 2018-11-07
- 0.1.3 — 2018-11-02
- 0.1.2 — 2018-11-02
- 0.1.1 — 2018-11-02
- 0.1.0 — 2018-11-02

## README

# Wait and go

Tiny util to create cached + "wait-on" callbacks

## Installation

```
yarn add wait-and-go
```

## Usage

```js
import createWaiter from "wait-and-go"

// Create a Hachi
const afterAuth = createWaiter("After you are authorized")

// Call it somewhere
afterAuth(token => {
  console.log("Authorized", token)
})

// Resolve anywhere
afterAuth.do(() => Promise.resolve("my-secret-token"))
```

## How it works?

It's just a more accurate version of:

```js
let resolver
let promise = new Promise(r => {
  resolver = r
})

const auth = () => {
  promise = Promise.resolve("my-secret-token")
  resolver(promise)
}

const afterAuth = cb => promise.then(cb)

afterAuth(token => {
  console.log("Authorized", token)
})
```

## React hook (WHY NOT LUL)

```js
import createWaiter from "wait-and-go"
import { useWaiter } from "wait-and-go/react"

const afterAuth = createWaiter("After you are authorized")

const UserInfo = () => {
  const { isLoaded, data } = useWaiter(afterAuth)

  return isLoaded && <span>{data.nickname}</span>
}

// Somewhere
afterAuth({ nickname: "Kelin2025" })
```

With some additions

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