Skip to content

Instantly share code, notes, and snippets.

@ken210
Last active November 16, 2017 09:48
Show Gist options
  • Save ken210/b44059069e1fc985527cf20d5fabfc27 to your computer and use it in GitHub Desktop.
Save ken210/b44059069e1fc985527cf20d5fabfc27 to your computer and use it in GitHub Desktop.
Middleware to run multiple middlewares in parallel
/**
* 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