# array-asyncify

> Async array functions

Latest version **0.0.7** (published 2017-06-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install array-asyncify
pnpm add array-asyncify
yarn add array-asyncify
bun add array-asyncify
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2017-06-26 |
| First published | 2017-06-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Qianba |
| Maintainers | qianba |
| Keywords | asyncify array, async map, async filter |

## Links

- npm: https://www.npmjs.com/package/array-asyncify
- npm.io page: https://npm.io/package/array-asyncify

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

- 0.0.7 (latest) — 2017-06-26
- 0.0.6 — 2017-06-21
- 0.0.5 — 2017-06-15
- 0.0.4 — 2017-06-14
- 0.0.3 — 2017-06-14
- 0.0.2 — 2017-06-14
- 0.0.1 — 2017-06-13
- 0.0.0 — 2017-06-13

## README

## Issue
We cannot use async function graceful in array methods such as `filter`,`map`,`reduce` and so on.

So the following code do not work
```javascript
let a=[1,2,3]
a.map(async (e)=>{
  //some async operations
  //await ...
  return e+1
})
.filter(async (e)=>{
  //some async operations
  return e%2===0
})
```

## Resolution 

```javascript
const { asyncify } = require("array-asyncify")
let delay = (t) => new Promise(res => setTimeout(res,t))
console.log("Example:");
(async () => {

  let a = asyncify([1, 2, 3])
  console.log("ret:")
  let ret = await a
    .map(async (e) => {
      await delay(100);
      return e + 1
    })
    .map(async (e) => {
      await delay(100)
      return e * 2
    })
  console.log(ret)

  try {
    let b = asyncify([1, Promise.resolve(2), 3])
    console.log("sum:", await b.reduce(async (p, n) => {
      console.log("p,n", p, n)
      return p + n
    }))
  } catch (e) {
    console.log(e)
  }


})()

```
## TODO
asyncify other method.

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