Skip to content

Instantly share code, notes, and snippets.

@MaxXxiMast
Created April 18, 2020 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaxXxiMast/7ea9db9cea12bf0e7bcbf1200b7d3223 to your computer and use it in GitHub Desktop.
Save MaxXxiMast/7ea9db9cea12bf0e7bcbf1200b7d3223 to your computer and use it in GitHub Desktop.
Process multiple values through a promise one by one
function processAll(){
return asyncAction.then(x => waitForEach(y => processFunc(y), x))
}
const waitForEach = (processFunc, [head, ...tail]) => {
!head
? Promise.resolve()
: processFunc(head).then(waitForEach(processFunc, tail))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment