Skip to content

Instantly share code, notes, and snippets.

@Deepak13245
Created June 2, 2020 18:54
Show Gist options
  • Save Deepak13245/c39c67c45abbf5d2a357fba5beeabbde to your computer and use it in GitHub Desktop.
Save Deepak13245/c39c67c45abbf5d2a357fba5beeabbde to your computer and use it in GitHub Desktop.
Run async functions in series
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