Last active
November 20, 2016 06:38
-
-
Save zspecza/ece6f961af15fd5c67acba0560d8a02b to your computer and use it in GitHub Desktop.
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 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