https://github.com/jeongbaebang/async-wave
비동기 콜백을 순차 실행 및 관리를 간소화하는 JavaScript 비동기 라이브러리
https://github.com/jeongbaebang/async-wave
async axios promise promise-chain typescript-definitions
Last synced: 4 months ago
JSON representation
비동기 콜백을 순차 실행 및 관리를 간소화하는 JavaScript 비동기 라이브러리
- Host: GitHub
- URL: https://github.com/jeongbaebang/async-wave
- Owner: jeongbaebang
- License: mit
- Created: 2023-05-01T04:39:22.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-11-18T00:54:43.000Z (8 months ago)
- Last Synced: 2025-11-18T02:27:15.738Z (8 months ago)
- Topics: async, axios, promise, promise-chain, typescript-definitions
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/async-wave
- Size: 921 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README-US.md
- License: LICENSE
Awesome Lists containing this project
README

`async-wave` is a safely executed asynchronous function that sequentially executes a chain of callback functions and returns the result. It safely transforms any value into a Promise and passes it as an argument to the asynchronous function. This allows for easy management of asynchronous operations and returning of results. Additionally, `asyncWave` provides intuitive implementation of error handling, success handling, and other logic through callback functions. This enables developers to write safe and efficient asynchronous code.
- [🇰🇷 한국어](./README.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
```
# 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';
// if a function is passed as the first argument and its return value is not a promise, an error will be thrown.
asyncWave([USER_NAME, getGithubUser, loadJson], {
onBefore: async () => {
await setFetchLog(); // Errors inside the handler are also caught! [1]
startLoadingIndicator();
},
onSuccess: async (githubUser) => {
await showAvatar(githubUser); // Errors inside the handler are also caught! [2]
console.log(`avatar_url: ${githubUser.avatar_url}`);
},
onError: (error) => {
console.error(error);
},
onSettled: () => {
endLoadingIndicator();
},
});
```
### Parameters
- callbacks: An array of callback functions to be executed in the then method. (**Note: If a function is passed as the first argument and its return value is not a promise, an error will be thrown.**)
- option (optional): An optional object that provides the following callback functions:
- onBefore: A function that runs before the promise starts. This function must be passed to the async function.
- onError: A function triggered when the promise reaches a rejected state.
- onSuccess: A function triggered when the promise reaches a resolved state. The result of the last promise is passed as an argument to this function.
- onSettled: A function triggered when the promise reaches either a resolved or a rejected state.
### Return Value
A Promise object that returns the result of the last promise in the chain.