'use strict';

// Module dependencies
const assert = require('assert');
const Promise = require('any-promise');

// Automatically or manually handle `next` according to fn's arguments length
module.exports = function wrapperFn(fn) {
  assert(typeof fn === 'function', 'Method fn must be a valid function');

  // Manually handle next
  if (fn.length > 1) return fn;

  // Automatically handle next
  return function(ctx, next) {
    return Promise.resolve(fn.call(this, ctx)).then(next);
  };
};

@@ -400,24 +400,85 @@
  return 
-function
+(new Function('fn', 'Promise', %60%0A    return function $%7Bfn.name %7C%7C ''%7D
 (ctx, ne
@@ -483,16 +483,18 @@
 next) %7B%0A
+  
     retu
@@ -546,14 +546,35 @@
 ext);%0A  
-%7D
+  %7D%60%0A  ))(fn, Promise)
 ;%0A%7D;%0A

optimize fn wrapper