Last active
September 5, 2019 17:16
-
-
Save seansullivan/06a810dd61e9cbb318c7f6607ded9795 to your computer and use it in GitHub Desktop.
Perform Async Action over Items using Async/Await
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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