Skip to content

Commit

Permalink
add createContext private api
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Apr 9, 2014
1 parent 1ae5db2 commit 21f9f52
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions index.js
Expand Up @@ -74,7 +74,6 @@ w.use = function (fn) {

w.run = function () {
debug('run');
var self = this;
var mw = [].concat(this.fns);
var args = slice.call(arguments);
var last = args[args.length - 1];
Expand All @@ -83,15 +82,28 @@ w.run = function () {
mw.push(callback || noop);
var gen = compose(mw);
var fn = co(gen);
var ctx = Object.create(this.context);
ctx.input = args;
var ctx = this.createContext(args, this);
fn.call(ctx, ctx.onerror);
return this;
};

/**
* Create a context.
*
* @param {Mixed} input
* @return {Object} ctx
* @api private
*/

w.createContext = function (input, self, ctx) {
ctx = Object.create(this.context);
ctx.input = input;
ctx.output = Object.create(null);
ctx.onerror = function (err) {
if (!err) return;
self.emit('error', err);
};
fn.call(ctx, ctx.onerror);
return this;
return ctx;
};

/**
Expand Down

0 comments on commit 21f9f52

Please sign in to comment.