Created
June 2, 2020 19:17
-
-
Save Deepak13245/e49c1853ebceacbd3ab6f725c42b4ba6 to your computer and use it in GitHub Desktop.
Running async functions in parallel
This file contains 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
function inParallel(list, fn) { | |
return Promise.all( | |
list.map(async (...args) => { | |
try{ | |
return { | |
status: true, | |
result: await fn(...args), | |
}; | |
}catch(error){ | |
return { | |
status: false, | |
result: error, | |
}; | |
} | |
}) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment