-
-
Save tingwei628/4b8adeff9049d23e09d9b12c384e453a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Compared to the form with Promise