Skip to content

Instantly share code, notes, and snippets.

@jwulf
Last active March 5, 2020 03:10
Show Gist options
  • Save jwulf/6e163088f80b3b59644ad7c1abbc81a6 to your computer and use it in GitHub Desktop.
Save jwulf/6e163088f80b3b59644ad7c1abbc81a6 to your computer and use it in GitHub Desktop.
async function myAsyncFunction(argument) {
const success = async res => ({ success: await res }) // Promise<{success: res}>
const error = async err => ({ error: await err }) // Promise<{error: e}>
const arrayTasks = [
{
run: async () => getDataAsync()
}
},
{
run: async () => getDataAsync()
}
]
const runWithResult = task => task.run().then(success).catch(error)
const outcomes = await Promise.all(arrayTasks.map(runWithResult))
console.log(outcomes) // array of {error: e} | {success: res}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment