composition

Compose generator and async/await middleware

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
composition
2.3.06 years ago8 years agoMinified + gzip package size for composition in KB

Readme

composition
!NPM versionnpm-imagenpm-url !Build statustravis-imagetravis-url !Test coveragecoveralls-imagecoveralls-url !Dependency Statusdavid-imagedavid-url !Licenselicense-imagelicense-url !Downloadsdownloads-imagedownloads-url
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);
})