{"id":18890032,"url":"https://github.com/shipshapecode/ember-async-await-for-each","last_synced_at":"2025-04-14T23:31:04.037Z","repository":{"id":57222996,"uuid":"153660020","full_name":"shipshapecode/ember-async-await-for-each","owner":"shipshapecode","description":"async/await aware forEach for Ember","archived":false,"fork":false,"pushed_at":"2019-08-15T21:21:09.000Z","size":320,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T18:57:03.036Z","etag":null,"topics":["async","await","ember-addon","foreach"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shipshapecode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-18T17:14:20.000Z","updated_at":"2019-08-15T21:21:05.000Z","dependencies_parsed_at":"2022-08-25T14:41:40.033Z","dependency_job_id":null,"html_url":"https://github.com/shipshapecode/ember-async-await-for-each","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipshapecode%2Fember-async-await-for-each","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipshapecode%2Fember-async-await-for-each/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipshapecode%2Fember-async-await-for-each/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipshapecode%2Fember-async-await-for-each/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shipshapecode","download_url":"https://codeload.github.com/shipshapecode/ember-async-await-for-each/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248978535,"owners_count":21192811,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","await","ember-addon","foreach"],"created_at":"2024-11-08T07:52:11.086Z","updated_at":"2025-04-14T23:31:03.624Z","avatar_url":"https://github.com/shipshapecode.png","language":"JavaScript","readme":"ember-async-await-for-each\n==============================================================================\n\u003ca href=\"https://shipshape.io/\"\u003e\u003cimg src=\"http://i.imgur.com/KVqNjgO.png\" alt=\"Ship Shape\" width=\"100\" height=\"100\"/\u003e\u003c/a\u003e\n\n**[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/)**.\n\n[![npm version](https://badge.fury.io/js/ember-async-await-for-each.svg)](http://badge.fury.io/js/ember-async-await-for-each)\n![Download count all time](https://img.shields.io/npm/dt/ember-async-await-for-each.svg)\n![npm](https://img.shields.io/npm/dm/ember-async-await-for-each.svg)\n[![Ember Observer Score](http://emberobserver.com/badges/ember-async-await-for-each.svg)](http://emberobserver.com/addons/ember-async-await-for-each)\n[![Build Status](https://travis-ci.org/shipshapecode/ember-async-await-for-each.svg)](https://travis-ci.org/shipshapecode/ember-async-await-for-each)\n[![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)\n[![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)\n\n`async/await` aware `forEach` for Ember. Concept taken from [this great article](https://codeburst.io/javascript-async-await-with-foreach-b6ba62bbf404)\non `async/await` in `forEach`.\n\nCompatibility\n------------------------------------------------------------------------------\n\n* Ember.js v3.4 or above\n* Ember CLI v2.13 or above\n* Node.js v8 or above\n\nInstallation\n------------------------------------------------------------------------------\n\n```\nember install ember-async-await-for-each\n```\n\n\nUsage\n------------------------------------------------------------------------------\nFirst you will want to import `asyncForEach`\n\n```js\nimport asyncForEach from 'ember-async-await-for-each';\n```\n\nYou can then use it inside of any `async` functions and await its result.\nAn example of how you could use it to save addresses for a person model is below.\n\n```js\nconst saveAddresses = async () =\u003e {\n  await asyncForEach(person.get('addresses').toArray(), async (address) =\u003e {\n    const address = await person.get('address');\n\n    if (address.get('isDirty')) {\n      return await address.save();\n    }\n  });\n};\n\nsaveAddresses();\n```\n\nYou can continue to wrap this in other `async` functions as well.\n\n```js\nconst doOtherAsyncStuff = async () =\u003e {\n  await saveAddresses();\n  await otherFunction();\n  // etc\n};\n```\n\n### Serial vs parallel execution\n`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.\n\nTo launch all callbacks in parallel, you would have to do something like below instead:\n\n```js\nimport { all } from 'rsvp';\n\nconst saveAddressesParallel = async () =\u003e {\n  await all(person.get('addresses').toArray().map(async (address) =\u003e {\n    const address = await person.get('address');\n\n    if (address.get('isDirty')) {\n      return await address.save();\n    }\n  }));\n};\n```\n\nContributing\n------------------------------------------------------------------------------\n\nSee the [Contributing](CONTRIBUTING.md) guide for details.\n\nLicense\n------------------------------------------------------------------------------\n\nThis project is licensed under the [MIT License](LICENSE.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshipshapecode%2Fember-async-await-for-each","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshipshapecode%2Fember-async-await-for-each","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshipshapecode%2Fember-async-await-for-each/lists"}