# @aster-js/async

> Aster async library part of Aster js library

Latest version **1.4.1** (published 2024-01-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install @aster-js/async
pnpm add @aster-js/async
yarn add @aster-js/async
bun add @aster-js/async
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.1 |
| Published | 2024-01-14 |
| First published | 2021-01-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 113.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | sebdoucet |
| Maintainers | aster-js |

## Links

- npm: https://www.npmjs.com/package/@aster-js/async
- Repository: https://github.com/asterlibraryjs/aster-js-async
- Homepage: https://github.com/asterlibraryjs/aster-js-async#readme
- Issues: https://github.com/asterlibraryjs/aster-js-async/issues
- npm.io page: https://npm.io/package/@aster-js/async

## Dependencies (3)

- [tslib](https://npm.io/package/tslib.md) ^2.6.2
- [@aster-js/core](https://npm.io/package/@aster-js/core.md) ^1.3.0
- [@aster-js/events](https://npm.io/package/@aster-js/events.md) ^1.3.0

## Recent versions

- 1.4.1 (latest) — 2024-01-14
- 1.4.0 — 2024-01-14
- 1.3.2 — 2024-01-13
- 1.3.0 — 2023-03-24
- 1.2.2 — 2022-01-22
- 1.2.1 — 2022-01-22
- 1.2.0 — 2022-01-22
- 1.1.2 — 2022-01-18
- 1.1.1 — 2022-01-18
- 1.1.0 — 2022-01-18
- 1.0.1 — 2021-02-07
- 1.0.0 — 2021-02-01
- 1.0.0-beta.1 — 2021-01-17

## README

# @aster-js/async

## Main concept

This library introduce a very important concept that will be used in more complexes Aster libraries: The `AbortToken`.

`AbortToken` allow to cancel cascading asynchronous calls and abort them as soon as possible and change the behavior:

```ts
async function update({ data, children }: CustomData, token: AbortToken): Promise<boolean> {

    // token.signal will allow to use native AbortController signal
    // Aborting during the request will reject the fetch call
    const response = await fetch("/data/", { method: "POST", body: JSON.stringify(data), signal: token.signal });
    const created = await response.json();

    // If the token is abort we choose to remove the data
    if(token.aborted) {
        await fetch(`/data/${created.id}`, { method: "DELETE" });
        return false;
    }

    // If not, we append its children
    await fetch(`/data/${created.id}/children`, { method: "POST", body: JSON.stringify(children) });
    return true;
}

```

## Other topics

- [Deferred](./doc/deferred.md)
- [Delayed](./doc/delayed.md)
- [Debouncer](./doc/debouncer.md)
- [Task](./doc/task.md)

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