Last active
November 16, 2017 09:48
-
-
Save ken210/b44059069e1fc985527cf20d5fabfc27 to your computer and use it in GitHub Desktop.
Middleware to run multiple middlewares in parallel
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
/** | |
* Runs multiple middlewares in parallel | |
* Usage: parallel(mw1, mw2, mw3); | |
*/ | |
const { after } = require("lodash"); | |
const parallel = (...fns) => (req, res, next) => { | |
const finalNext = after(fns.length, next); | |
fns.forEach(fn => fn(req, res, finalNext)); | |
}; | |
module.exports = parallel; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment