Ware inspired, easily create your own middleware layer using generators via co.
var ware = require('..');
var w = ware()
.use(function *(next) {
this.x = 'hello';
yield next;
})
.use(function *(next) {
this.y = 'world';
yield next;
})
.use(function *(next) {
yield next;
});
w.run({}, {}, function *() {
console.log(this.x, this.y);
});
Print the arguments of input.
var ware = require('..');
var w = ware()
.use(function *(next) {
console.log(this.input); // 1, 2, 3
yield next;
});
w.run(1, 2, 3);
Handles error.
var ware = require('..');
var w = ware()
.use(function *(next) {
if ('42' != this.input[0].life) throw new Error();
yield next;
})
.use(function *(next) {
console.log('yes!');
})
.on('error', function (err) {
console.log('no!');
});
w.run({ life: '41' }); // "no!"
w.run({ life: '42' }); // "yes!"
Create a new list of middleware.
Push a middleware fn(GeneratorFunction) onto the list. If the middleware has an arity of one more than the input to run it's an error middleware.
Runs the middleware functions with input... and optionally calls callback(GeneratorFunction).
Clear the middleware.
MIT