1.0.4 • Published 9 years ago

adonis-co-ware v1.0.4

Weekly downloads
6
License
MIT
Repository
github
Last release
9 years ago

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

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago