Skip to content

Instantly share code, notes, and snippets.

@seansullivan
Last active September 5, 2019 17:16
Show Gist options
  • Save seansullivan/06a810dd61e9cbb318c7f6607ded9795 to your computer and use it in GitHub Desktop.
Save seansullivan/06a810dd61e9cbb318c7f6607ded9795 to your computer and use it in GitHub Desktop.
Perform Async Action over Items using Async/Await
const results = await items.reduce(async (previousPromise, item) => {
const collection = await previousPromise;
try {
const result = await doSomethingAsync(item);
collection.successes.push(result);
} catch(e) {
collection.errors.push(e);
}
return collection;
}, Promise.resolve({successes: [], errors: []}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment