# async-lube

> Simplify Asynchronous Operations in JavaScript

Latest version **1.6.0** (published 2023-11-10) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2023-11-10 |
| First published | 2023-06-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 47.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | artxe2 |
| Maintainers | artxe2 |
| Keywords | async, lube, async-lube, dag, decorator, parallel, promise, syntax sugar |

## Links

- npm: https://www.npmjs.com/package/async-lube
- Repository: https://github.com/Artxe2/lube-series
- Homepage: https://github.com/Artxe2/lube-series#readme
- Issues: https://github.com/Artxe2/lube-series/issues
- npm.io page: https://npm.io/package/async-lube

## 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

- 1.6.0 (latest) — 2023-11-10
- 1.5.2 — 2023-10-16
- 1.5.1 — 2023-10-15
- 1.4.2 — 2023-09-15
- 1.4.1 — 2023-09-11
- 1.4.0 — 2023-09-11
- 1.3.0 — 2023-08-31
- 1.2.0 — 2023-08-28
- 1.1.1 — 2023-08-14
- 1.1.0 — 2023-08-09
- 1.0.0 — 2023-08-06
- 0.2.0 — 2023-08-04
- 0.1.6 — 2023-07-29
- 0.1.5 — 2023-07-07
- 0.1.4 — 2023-06-30
- … 3 more at https://npm.io/package/async-lube/versions

## README

# Async Lube
## Simplify Asynchronous Operations in JavaScript
Managing asynchronous operations in JavaScript can often be complex and error-prone, especially when dealing with dependencies and handling handlers.  
However, with the **"async-lube"** library, working with asynchronous code becomes a seamless experience.  
This powerful JavaScript library provides a set of functions that simplify asynchronous operations and empower developers to write clean and efficient code.
<br>
<br>

## installation
```bash
npm i async-lube
```
```bash
pnpm i async-lube
```
```bash
bun i async-lube
```

## How to use
### Ergonomic fetch api
```ts
import { client } from "async-lube"

client("https://...", abort => setTimeout(abort, 2000))
    .get({ cache: "default" })
    .query({ id: 1 }, { Authorization: "..." })
    .then(res => res.json())

client("https://...")
    .post({ cache: "default" })
    .json({ string: "abc", number: 123 })
    .then(res => res.json())
```

### Ensure execution order of complex asynchronous flows with DAG
```ts
import { dag } from "async-lube"

async function func_a(): string {
    return ""
}
function func_b(a: string): number {
    return +a
}
let count = 0
async function func_c(a: string, b: number) {
    return ++count + a + b
}

var async_flow = dag()
    .add(func_a)
    .add(func_b, func_a)
    .add(func_c, func_a, func_b)

await async_flow() //=> "10"
await async_flow() //=> "20"
await async_flow() //=> "30"

var type_error_flow = dag()
    .add(func_a, "") // Expected 1 arguments, but got 2.ts(2554)
    .add(func_b) // Expected 2 arguments, but got 1.ts(2554)
    .add(func_b, 1) // Argument of type 'number' is not assignable to parameter of type ...ts(2345)
```

### Simplifies complex asynchronous functionality with Decorator
```ts
import { decorator } from "async-lube"

var api = decorator((id: string) => fetch("https://.../" + id))
    .cache(10) // s
    .debounce(200) // ms
    .retries((reason, count) => {
        if (count > 3) {
            throw reason // throwing an error does not retry
        }
    })
    .throttle(3, 500) // n request in ms

api("123") // caching key: "[\"123\"]"

api(123) // Argument of type 'number' is not assignable to parameter of type 'string'.ts(2345)
api() // Expected 1 arguments, but got 0.ts(2554)
```

### Parallel runs that limit the maximum number of concurrent runs
```ts
import { parallel } from "async-lube"

parallel(2, () => ({ a: "a", b: "b" }), () => 123, () => {})
    .then(result => {
        if ("value" in result[0]) {
            result[0].value.a
        } else {
            throw result.reason
        }
        if ("value" in result[1]) {
            result[1].value.toFixed()
        } else {
            throw result.reason
        }
        if ("value" in result[2]) {
            result[2].value[""] // Property '' does not exist on type 'void'.ts(7053)
        }
    })
```

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