composition
Compose generator and async/await middleware
Last updated 2 years ago by jongleberry .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install composition 
SYNC missed versions from official npm registry.

composition

NPM version Build status Test coverage Dependency Status License Downloads

Compose generator and async/await middleware like koa. Allows to use both generator functions and async/await functions.

var compose = require('composition');

var stack = [];

// generator functions
stack.push(function* (next) {
  yield next;
});

// regular functions that return anything
// but they should be promises!
stack.push(function (next) {
  return Promise.resolve(true);
});

// async/await functions
stack.push(async function (next) {
  return await Promise.resolve(true);
});

// compose it into a function
var fn = compose(stack);

// this function returns a promise
fn.call(this).then(function (val) {
  console.log(val);
}).catch(function (err) {
  console.error(err.stack);
  process.exit(1);
})
Downloads
Today 36
This Week 2,947
This Month 6,898
Last Day 163
Last Week 3,273
Last Month 13,039
Dependencies (2)
Dev Dependencies (6)

Copyright 2014 - 2017 © taobao.org |