adonis-co-ware
Fork of co-ware to make it work with adonis framework
Last updated 2 years ago by amanvirk .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install adonis-co-ware 
SYNC missed versions from official npm registry.

co-ware Build Status

Ware inspired, easily create your own middleware layer using generators via co.

Examples

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!"

API

ware()

Create a new list of middleware.

.use(*fun)

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.

.run(input..., [GeneratorFunction])

Runs the middleware functions with input... and optionally calls callback(GeneratorFunction).

.clear()

Clear the middleware.

License

MIT

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 10
Dependencies (2)
Dev Dependencies (2)

Copyright 2014 - 2016 © taobao.org |