# async-wave

> A sequential method chain for asynchronous execution of callback functions, safely converting and passing any value as a promise.

Latest version **1.8.6** (published 2024-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-wave
pnpm add async-wave
yarn add async-wave
bun add async-wave
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.8.6 |
| Published | 2024-07-19 |
| First published | 2023-08-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 37.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | jeongbaebang |
| Maintainers | jeongbaebang |
| Keywords | typescript, promise |

## Links

- npm: https://www.npmjs.com/package/async-wave
- Repository: https://github.com/jeongbaebang/async-wave
- Issues: https://github.com/jeongbaebang/async-wave/issues
- npm.io page: https://npm.io/package/async-wave

## Dependencies (6)

- [is-promise](https://npm.io/package/is-promise.md) ^4.0.0
- [lodash.add](https://npm.io/package/lodash.add.md) ^3.7.0
- [lodash.size](https://npm.io/package/lodash.size.md) ^4.2.0
- [lodash.isequal](https://npm.io/package/lodash.isequal.md) ^4.5.0
- [lodash.clonedeep](https://npm.io/package/lodash.clonedeep.md) ^4.5.0
- [lodash.isfunction](https://npm.io/package/lodash.isfunction.md) ^3.0.9

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.8.6 (latest) — 2024-07-19
- 1.8.5 — 2024-07-05
- 1.8.3 — 2024-07-04
- 1.8.2 — 2024-07-04
- 1.8.1 — 2024-07-04
- 1.8.0 — 2024-07-04
- 1.7.2 — 2024-04-06
- 1.7.1 — 2024-04-04
- 1.7.0 — 2024-04-04
- 1.6.0 — 2024-03-30
- 1.5.5 — 2023-08-16
- 1.5.4 — 2023-08-16
- 1.5.3 — 2023-08-16

## README

<h1 align="center">
   <b>
      <img src="assets/async-wave.png" alt="async-wave logo" style="height: 300px; width:300px; border-radius: 50px;"/><br>
   </b>
</h1>

<p align="center">"async-wave"는 안전하고 효율적인 비동기 코드 작성을 위해, 콜백 함수를 메서드 체인으로 연결하여 순차적으로 실행하고 처리 결과를 반환하는 비동기 함수입니다. 이를 통해 다양한 비동기 작업을 간편하게 처리할 수 있습니다.</p>

- [🇺🇸 English](./README-US.md)

## Table of Contents

- [Installing](#installing)
  - [Package manager](#package-manager)
  - [CDN](#cdn)
- [Usage](#Usage)

## Installing

### Package manager

Using npm:

```bash
$ npm install async-wave
```

Using yarn:

```bash
$ yarn add async-wave
```

### CDN

Using unpkg CDN:

```html
<script src="https://unpkg.com/async-wave@{{VERSION}}/dist/bundle.js"></script>
```

## Usage

### Before

```ts
// Promises chaining
await setFetchLog();
startLoadingIndicator();
getGithubUser(USER_NAME)
  .then(loadJson)
  .then(showAvatar)
  .then((githubUser) => console.log(`avatar_url: ${githubUser.avatar_url}`))
  .catch((error) => console.error(error))
  .finally(endLoadingIndicator);
```

### After

```typescript
import { asyncWave } from 'async-wave';

// 첫번째 인수는 어떤 값을 전달하든 항상 프로미스로 감싸져서 전달됩니다.
asyncWave<GithubUser>([USER_NAME, getGithubUser, loadJson], {
  onBefore: async () => {
    await setFetchLog(); // 핸들러 내부 에러도 캐치됩니다! [1]
    startLoadingIndicator();
  },
  onSuccess: async (githubUser) => {
    await showAvatar(githubUser); // 핸들러 내부 에러도 캐치됩니다! [2]
    console.log(`avatar_url: ${githubUser.avatar_url}`);
  },
  onError: (error) => {
    console.error(error);
  },
  onSettled: () => {
    endLoadingIndicator();
  },
});
```

### Parameters

- callbacks: then 메서드에서 실행할 콜백 함수들의 배열입니다. (**참고: 첫번째 인수는 어떤 값을 전달하든 항상 프로미스로 감싸져서 전달됩니다.**)
- option (선택 사항): 다음 콜백 함수들을 제공하는 선택적인 객체입니다:
  - onBefore: 프로미스가 시작되기 전에 실행되는 함수입니다. 해당 함수는 async 함수로 전달해야 합니다.
  - onError: 프로미스가 거부된 상태에 도달했을 때 실행되는 함수입니다.
  - onSuccess: 프로미스가 해결된 상태에 도달했을 때 실행되는 함수입니다. 마지막 프로미스의 결과가 이 함수의 인자로 전달됩니다.
  - onSettled: 프로미스가 해결되거나 거부된 상태에 도달했을 때 실행되는 함수입니다.

### Return Value

체인에서 마지막 프로미스의 결과를 반환하는 Promise 객체입니다.

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