co-ware

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

MIT 12 个版本
安装
npm install co-ware
yarn add co-ware
pnpm add co-ware
bun add co-ware
README

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.6.0 2015-01-28
1.5.3 2014-08-25
1.5.2 2014-08-25
1.5.1 2014-08-25
1.5.0 2014-08-23
1.3.0 2014-04-15
1.2.0 2014-04-09
1.1.0 2014-04-07
1.0.2 2014-04-07
1.0.1 2014-04-07
1.0.0 2014-04-07
0.0.0 2014-03-11