plugins/dispatcher/dispatcher.js
function wrapAsyncFunction(fn, isSubAction) {
        if (!fn || fn.__asyncWrapped__) {
            return fn;
        }
        var wrapedFn = fn;
        if (typeof fn === 'function') {
            wrapedFn = function asyncWrap(req, res, next) {
                var maybePromise = fn(req, res, next);
                if (maybePromise && maybePromise.catch && typeof maybePromise.catch === 'function') {
                    maybePromise.catch(next);
                }
            };
        }
        for (var key in fn) {
            if (fn.hasOwnProperty(key)) {
                if (!isSubAction && VERB[key.toLowerCase()]) {
                    // 仅在顶级Action中自动寻找VERB Action进行异步包裹
                    wrapedFn[key] = wrapAsyncFunction(fn[key], true);
                } else {
                    // 其余对象仅复制
                    wrapedFn[key] = fn[key];
                }
            }
        }
        wrapedFn.__asyncWrapped__ = true;
        return wrapedFn;
    }
function wrapAsyncFunction(fn, isSubAction) {
        if (!fn || fn.__asyncWrapped__) {
            return fn;
        }
        var wrapedFn = fn;
        if (typeof fn === 'function') {
            wrapedFn = function asyncWrap(req, res, next) {
                var maybePromise = fn(req, res, next);
                if (maybePromise && maybePromise.catch && typeof maybePromise.catch === 'function') {
                    maybePromise.catch(next);
                }
            };
        }
        for (var key in fn) {
            if (fn.hasOwnProperty(key)) {
                if (!isSubAction && VERB[key.toLowerCase()]) {
                    // 仅在顶级Action中自动寻找VERB Action进行异步包裹
                    wrapedFn[key] = wrapAsyncFunction(fn[key], true);
                } else {
                    // 其余对象仅复制
                    wrapedFn[key] = fn[key];
                }
            }
        }
        wrapedFn.__asyncWrapped__ = true;
        return wrapedFn;
    }
function wrapAsyncFunction ( fn , isSubAction ) { if ( ! fn || fn . __asyncWrapped__ ) { return fn ; } var wrapedFn = fn ; if ( typeof fn === 'function' ) { wrapedFn = function asyncWrap ( req , res , next ) { var maybePromise = fn ( req , res , next ) ; if ( maybePromise && maybePromise . catch && typeof maybePromise . catch === 'function' ) { maybePromise . catch ( next ) ; } } ; } for ( var key in fn ) { if ( fn . hasOwnProperty ( key ) ) { if ( ! isSubAction && VERB [ key . toLowerCase ( ) ] ) { // 仅在顶级Action中自动寻找VERB Action进行异步包裹 wrapedFn [ key ] = wrapAsyncFunction ( fn [ key ] , true ) ; } else { // 其余对象仅复制 wrapedFn [ key ] = fn [ key ] ; } } } wrapedFn . __asyncWrapped__ = true ; return wrapedFn ; }
warp a action method to catch async error
@param  {Function} fn [description]
@return {[type]}      [description]
warp a action method to catch async error