lib/server/apiadapter-mixin.js
function processCallbacks(namedRouteParameters, data, req, res, successHandler
	, errorHandler, callbacks) {
	debug('processing callbacks (url: `%s`, namedRouteParameters: `%s`,' +
		' data: `%j`)', req.url, namedRouteParameters, data);

	var callbackScope = {
			app: req.app
			, req: req
		}
		, handlerScope = {
			app: req.app
			, req: req
			, res: res
		}
		, callbackArguments = _.union(
			successHandler.bind(handlerScope)
			, errorHandler.bind(handlerScope)
			, namedRouteParameters
			, data
		)
		, index = -1
		, executeCallback = function executeCallback(callback) {
			callback.apply(callbackScope, callbackArguments);
		}
		, runner;

	if(!_.isArray(callbacks)) {
		runner = function() { executeCallback(callbacks); };
	} else {
		var finalSuccessHandler = callbackArguments[0]
			, stackedSuccessHandler = function stackedSuccessHandler() {
				index += 1;

				if(index < callbacks.length) {
					executeCallback(callbacks[index]);
				} else {
					finalSuccessHandler.apply(handlerScope, arguments);
				}
			};

		callbackArguments[0] = stackedSuccessHandler;
		runner = stackedSuccessHandler;
	}

	try {
		runner();
	} catch(err) {
		winston.log('error', 'API callback caused exceptional error', {
					source: toString()
					, apiRoute: req.originalUrl
					, err: err.toString() || err
					, stack: err.stack || undefined
				});
		errorHandler.call(handlerScope, err);
	}
}
function processCallbacks(namedRouteParameters, data, req, res, successHandler
	, errorHandler, callbacks) {
	debug('processing callbacks (url: `%s`, namedRouteParameters: `%s`,' +
		' data: `%j`)', req.url, namedRouteParameters, data);

	var callbackScope = {
			app: req.app
			, req: req
		}
		, handlerScope = {
			app: req.app
			, req: req
			, res: res
		}
		, callbackArguments = _.union(
			successHandler.bind(handlerScope)
			, errorHandler.bind(handlerScope)
			, namedRouteParameters
			, data
		)
		, index = -1
		, executeCallback = function executeCallback(callback) {
			callback.apply(callbackScope, callbackArguments);
		}
		, runner;

	if(!_.isArray(callbacks)) {
		runner = function() { executeCallback(callbacks); };
	} else {
		var finalSuccessHandler = callbackArguments[0]
			, stackedSuccessHandler = function stackedSuccessHandler() {
				index += 1;

				if(index < callbacks.length) {
					executeCallback(callbacks[index]);
				} else {
					finalSuccessHandler.apply(handlerScope, arguments);
				}
			};

		callbackArguments[0] = stackedSuccessHandler;
		runner = stackedSuccessHandler;
	}

	try {
		runner();
	} catch(err) {
		winston.log('error', 'API callback caused exceptional error', {
					source: toString()
					, apiRoute: req.originalUrl
					, err: err.toString() || err
					, stack: err.stack || undefined
				});
		errorHandler.call(handlerScope, err);
	}
}
function processCallbacks ( namedRouteParameters , data , req , res , successHandler , errorHandler , callbacks ) { debug ( 'processing callbacks (url: `%s`, namedRouteParameters: `%s`,' + ' data: `%j`)' , req . url , namedRouteParameters , data ) ; var callbackScope = { app : req . app , req : req } , handlerScope = { app : req . app , req : req , res : res } , callbackArguments = _ . union ( successHandler . bind ( handlerScope ) , errorHandler . bind ( handlerScope ) , namedRouteParameters , data ) , index = - 1 , executeCallback = function executeCallback ( callback ) { callback . apply ( callbackScope , callbackArguments ) ; } , runner ; if ( ! _ . isArray ( callbacks ) ) { runner = function ( ) { executeCallback ( callbacks ) ; } ; } else { var finalSuccessHandler = callbackArguments [ 0 ] , stackedSuccessHandler = function stackedSuccessHandler ( ) { index += 1 ; if ( index < callbacks . length ) { executeCallback ( callbacks [ index ] ) ; } else { finalSuccessHandler . apply ( handlerScope , arguments ) ; } } ; callbackArguments [ 0 ] = stackedSuccessHandler ; runner = stackedSuccessHandler ; } try { runner ( ) ; } catch ( err ) { winston . log ( 'error' , 'API callback caused exceptional error' , { source : toString ( ) , apiRoute : req . originalUrl , err : err . toString ( ) || err , stack : err . stack || undefined } ) ; errorHandler . call ( handlerScope , err ) ; } }
PrivateFunction: processCallbacks
This function is used to run a callback function or an array of stacked
callback functions which are registered for an API route.

Parameters:
(Object) namedRouteParameters - If a route contains named parameters
(stuff like ":id", ":name"), this object
should contain these values. They are
passed as arguments to each callback
function.
(Object) data - The data argument contains any larger data amount. Stuff
like the body of a POST request in example.
(Object) req - ExpressJS request object is needed for creating scope
objects for callback execution
(Object) res - ExpressJS response object is needed for creating the scope
object for calling the handler functions.
(Function) successHandler - A function which is injected as the first
argument when executing the callback
(Function) errorHandler - A function which is injected as the second
argument when executing the callback
(Function)/(Array) callbacks - An API function which should be executed.
If you pass an array with functions, each
function gets executed as it is stacked
upon the array. Calling success will
proceed, error will stop execution.
Make sure you call one of them or your
code will go nuts.
PrivateFunction : processCallbacks This function is used to run a callback function or an array of stacked callback functions which are registered for an API route .