# @kev_nz/async-tools

> Async tools - a collection of utility functions for working with async/await code.

Latest version **1.3.0** (published 2020-07-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @kev_nz/async-tools
pnpm add @kev_nz/async-tools
yarn add @kev_nz/async-tools
bun add @kev_nz/async-tools
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2020-07-12 |
| First published | 2019-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 24.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Kevin Isom |
| Maintainers | kev_nz |
| Keywords | async, await, utils, functional, composition, functional composition, asynchronous, async tools, promises, helpers |

## Links

- npm: https://www.npmjs.com/package/@kev_nz/async-tools
- Repository: https://github.com/Kevnz/async-tools
- Homepage: https://kevinisom.info/async-tools
- Issues: https://github.com/Kevnz/async-tools/issues
- npm.io page: https://npm.io/package/@kev_nz/async-tools

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@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

## Recent versions

- 1.3.0 (latest) — 2020-07-12
- 1.2.3 — 2019-07-22
- 1.2.2 — 2019-07-22
- 1.2.1 — 2019-04-28
- 1.2.0 — 2019-04-25
- 1.1.1 — 2019-04-18
- 1.1.0 — 2019-04-18
- 1.0.3 — 2019-04-14
- 1.0.2 — 2019-04-14
- 1.0.1 — 2019-04-04
- 1.0.0 — 2019-04-04

## README

# Async Tools

[![npm version](https://badge.fury.io/js/%40kev_nz%2Fasync-tools.svg)](https://badge.fury.io/js/%40kev_nz%2Fasync-tools) ![Build Status](https://img.shields.io/circleci/project/github/Kevnz/async-tools/master.svg) [![Coverage Status](https://coveralls.io/repos/github/Kevnz/async-tools/badge.svg?branch=master)](https://coveralls.io/github/Kevnz/async-tools?branch=master)

This is a collection of utility functions for working with async/await code.

## Install

```
npm install @kev_nz/async-tools
```

## API Usage

Here are the functions provided. Additionally feel free to look at the tests in the project as well.

### Delay

The delay method allows you to use wait a number of milliseconds before continuing the exection of your code.

```javascript
const { delay } = require('@kev_nz/async-tools')

(async () => {
  await delay(100)
  console.info('~100 milliseconds later')
})()

```

### Mapper

Execute an asynchronous mapping function over an array of returning the result.

```javascript
const { mapper } = require('@kev_nz/async-tools')

(async () => {

  const items = [1, 2, 3]
  const mappedItems = await mapper(items, anAsynchronousFunction)
  // passing in an additional concurrency value specifies the number of async methods executed at a time
  const mappedItemsAgain = await mapper(items, anAsynchronousFunction, 2)
})()
```

### Reducer

Execute asynchronous reducer functions over a starting value.

```javascript
const { delay, reducer } = require('@kev_nz/async-tools')

const anAsyncFunction = async val => {
  await delay(10)
  return val + 1
}
(async () => {
  const finalValue = await reducer(0,
    anAsyncFunction,
    anAsyncFunction,
    anAsyncFunction
  )
  //finalValue 3
})()
```

### Each

Execute an asynchronous function over an array one item at a time.

```javascript
const { each } = require('@kev_nz/async-tools')

(async () => {
  const items = [1, 2, 3]
  const [first, second, third] = await each(items, anAsyncFunction)
})()
```

### Composer

Take number of functions and compose them together.

```javascript
const { composer } = require('@kev_nz/async-tools')

const anAsyncFunction = async val => {
  await delay(10)
  return val + 1
}
const anotherAsyncFunction = async val => {
  await delay(10)
  return val + 2
}

(async () => {
  const asyncChain = composer(
    anAsyncFunction,
    anotherAsyncFunction,
    anAsyncFunction
  )
  const finalValue = await asyncChain(0)
  //finalValue 4
})()
```

### Holder

When used with composer it lets you pass additional parameters to a function in the composed.

```javascript
const { composer, holder } = require('@kev_nz/async-tools')

const anAsyncFunction = async val => {
  await delay(10)
  return val + 1
}
const anotherAsyncFunction = async (val, secondValue) => {
  await delay(10)
  return val + secondValue
}

(async () => {
  const asyncChain = composer(
    anAsyncFunction,
    holder(anotherAsyncFunction, 3),
    anAsyncFunction
  )
  const finalValue = await asyncChain(0)
  //finalValue 5
})()
```

### Timeout

Take number of functions and compose them together.

```javascript
const { timeout } = require('@kev_nz/async-tools')

(async () => {
  const result = await timeout(() => thingThatIsLongRunning())

})()
```

### Do While

Execute an async function while a condition is true

```javascript
const { doWhile } = require('@kev_nz/async-tools')

(async () => {
  const results = await doWhile(async () => {
    await asyncFunction()
  }, () => something === true)
})()
```

### While Do

While a condition is true execute an async function

```javascript
const { whileDo } = require('@kev_nz/async-tools')

(async () => {
  const results = await whileDo(
    () => something === true),
    async () => {
      await asyncFunction()
    })
})()
```

### Test Coverage

* [Coveralls](https://coveralls.io/github/Kevnz/async-tools?branch=master)
* [Coverage Results](http://kevinisom.info/async-tools/coverage/lcov-report/)

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