src/routes.js
function join_plugins(plugins) {
	debug.assert(plugins).is('array');
	debug.assert( ARRAY(plugins).every(is.func) ).equals(true);

	return function join_plugins_(req, res, next) {
		var queue = [].concat(plugins);

		function do_iteration_() {
			if(queue.length === 0) {
				next();
				return;
			}
			var plugin = queue.shift();
			debug.assert(plugin).is('function');
			plugin(req, res, function plugin_wrapper(err) {
				if(err) {
					next(err);
					return;
				}
				do_iteration_();
			});
		}

		function do_iteration() {
			try {
				do_iteration_();
			} catch(err) {
				next(err);
				return;
			}
		}

		do_iteration();
	};
}
function join_plugins(plugins) {
	debug.assert(plugins).is('array');
	debug.assert( ARRAY(plugins).every(is.func) ).equals(true);

	return function join_plugins_(req, res, next) {
		var queue = [].concat(plugins);

		function do_iteration_() {
			if(queue.length === 0) {
				next();
				return;
			}
			var plugin = queue.shift();
			debug.assert(plugin).is('function');
			plugin(req, res, function plugin_wrapper(err) {
				if(err) {
					next(err);
					return;
				}
				do_iteration_();
			});
		}

		function do_iteration() {
			try {
				do_iteration_();
			} catch(err) {
				next(err);
				return;
			}
		}

		do_iteration();
	};
}
Join multiple Express plugins into one