Created
October 26, 2013 08:24
-
-
Save Radagaisus/7166739 to your computer and use it in GitHub Desktop.
parallel middlewares
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
async = require 'async' | |
# The `parallel` middleware allows to run several middlewares in parallel. | |
# It does this by simply using AsyncJS' `applyEach` on the middlewares. | |
# | |
# The middlewares will receive 3 parameters: `request`, `response` and | |
# `next`, in the same way and order they usually get them. As the | |
# execution is in parallel, if one of the middlewares will have an error | |
# the second one will continue to execute. If an error is passed to the | |
# `next` callback it will be passed correctly forward. | |
# | |
# Example usage: | |
# | |
# @get '/connect/facebook/callback', | |
# controllers.players.authentication.facebook, | |
# middlewares.parallel( | |
# controllers.players.authentication.update_gender_statistics, | |
# middlewares.background_jobs.queue | |
# ) | |
# | |
# See AsyncJS docs for more info: https://github.com/caolan/async#applyEach | |
# | |
module.exports = parallel = (middlewares...) -> | |
return (req, res, next) -> | |
async.applyEach middlewares, req, res, (err) -> | |
next(error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment