# ember-async-await-for-each

> async/await aware forEach for Ember

Latest version **0.1.1** (published 2019-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install ember-async-await-for-each
pnpm add ember-async-await-for-each
yarn add ember-async-await-for-each
bun add ember-async-await-for-each
```

## 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.1.1 |
| Published | 2019-08-15 |
| First published | 2018-10-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 8.* \|\| >= 10.* |
| Dependencies | 1 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Robert Wagner |
| Maintainers | rwwagner90 |
| Keywords | async, await, async/await, ember-addon, forEach |

## Links

- npm: https://www.npmjs.com/package/ember-async-await-for-each
- Repository: https://github.com/shipshapecode/ember-async-await-for-each
- Homepage: https://github.com/shipshapecode/ember-async-await-for-each#readme
- Issues: https://github.com/shipshapecode/ember-async-await-for-each/issues
- npm.io page: https://npm.io/package/ember-async-await-for-each

## Dependencies (1)

- [ember-cli-babel](https://npm.io/package/ember-cli-babel.md) ^7.7.3

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

- 0.1.1 (latest) — 2019-08-15
- 0.1.0 — 2019-01-24
- 0.0.2 — 2018-10-19
- 0.0.1 — 2018-10-18
- 0.0.0 — 2018-10-18

## README

ember-async-await-for-each
==============================================================================
<a href="https://shipshape.io/"><img src="http://i.imgur.com/KVqNjgO.png" alt="Ship Shape" width="100" height="100"/></a>

**[ember-async-await-for-each is built and maintained by Ship Shape. Contact us for Ember.js consulting, development, and training for your project](https://shipshape.io/ember-consulting/)**.

[![npm version](https://badge.fury.io/js/ember-async-await-for-each.svg)](http://badge.fury.io/js/ember-async-await-for-each)
![Download count all time](https://img.shields.io/npm/dt/ember-async-await-for-each.svg)
![npm](https://img.shields.io/npm/dm/ember-async-await-for-each.svg)
[![Ember Observer Score](http://emberobserver.com/badges/ember-async-await-for-each.svg)](http://emberobserver.com/addons/ember-async-await-for-each)
[![Build Status](https://travis-ci.org/shipshapecode/ember-async-await-for-each.svg)](https://travis-ci.org/shipshapecode/ember-async-await-for-each)
[![Code Climate](https://codeclimate.com/github/shipshapecode/ember-async-await-for-each/badges/gpa.svg)](https://codeclimate.com/github/shipshapecode/ember-async-await-for-each)
[![Test Coverage](https://codeclimate.com/github/shipshapecode/ember-async-await-for-each/badges/coverage.svg)](https://codeclimate.com/github/shipshapecode/ember-async-await-for-each/coverage)

`async/await` aware `forEach` for Ember. Concept taken from [this great article](https://codeburst.io/javascript-async-await-with-foreach-b6ba62bbf404)
on `async/await` in `forEach`.

Compatibility
------------------------------------------------------------------------------

* Ember.js v3.4 or above
* Ember CLI v2.13 or above
* Node.js v8 or above

Installation
------------------------------------------------------------------------------

```
ember install ember-async-await-for-each
```


Usage
------------------------------------------------------------------------------
First you will want to import `asyncForEach`

```js
import asyncForEach from 'ember-async-await-for-each';
```

You can then use it inside of any `async` functions and await its result.
An example of how you could use it to save addresses for a person model is below.

```js
const saveAddresses = async () => {
  await asyncForEach(person.get('addresses').toArray(), async (address) => {
    const address = await person.get('address');

    if (address.get('isDirty')) {
      return await address.save();
    }
  });
};

saveAddresses();
```

You can continue to wrap this in other `async` functions as well.

```js
const doOtherAsyncStuff = async () => {
  await saveAddresses();
  await otherFunction();
  // etc
};
```

### Serial vs parallel execution
`asyncForEach` resolves the callbacks in a serial fashion. This means that it waits until a callback is fully resolved before moving onto the next element in the list.

To launch all callbacks in parallel, you would have to do something like below instead:

```js
import { all } from 'rsvp';

const saveAddressesParallel = async () => {
  await all(person.get('addresses').toArray().map(async (address) => {
    const address = await person.get('address');

    if (address.get('isDirty')) {
      return await address.save();
    }
  }));
};
```

Contributing
------------------------------------------------------------------------------

See the [Contributing](CONTRIBUTING.md) guide for details.

License
------------------------------------------------------------------------------

This project is licensed under the [MIT License](LICENSE.md).

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