Created
June 2, 2020 18:54
-
-
Save Deepak13245/c39c67c45abbf5d2a357fba5beeabbde to your computer and use it in GitHub Desktop.
Run async functions in series
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 inSeries(list, fn) { | |
return list.reduce(async (acc, ...rest) => { | |
const results = await acc; | |
try{ | |
results.push({ | |
status: true, | |
result: await fn(...rest), | |
}); | |
}catch(error){ | |
results.push({ | |
status: false, | |
result: error, | |
}); | |
} | |
return results; | |
}, Promise.resolve([])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment