Skip to content

Instantly share code, notes, and snippets.

@zspecza
Last active November 20, 2016 06:38
Show Gist options
  • Save zspecza/ece6f961af15fd5c67acba0560d8a02b to your computer and use it in GitHub Desktop.
Save zspecza/ece6f961af15fd5c67acba0560d8a02b to your computer and use it in GitHub Desktop.
function sequentialCallback (...fns) {
return (...args) => {
const done = args.pop()
const next = (error, ...args) => {
if (error) return done(error)
if (fns.length) {
const fn = fns.shift()
return fn(...args, next)
}
return done(null, ...args)
}
return next(null, ...args)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment