midd-compose

0.1.0 • Public • Published

Compose use-* middlewares

Compose middlewares like (req, resp, next)=>Promise into one.

Examples

const compose = require('midd-compose');
const stack = compose([
  async (req, resp, next)=>{
    await sleep(1);
    const result = await next()
    await sleep(1);
    return result;
  },
  (req, resp, next)=>{
    return new Promise((resolve, reject)=>{
      resolve(1)
    })
  }
])
 
//call the composed one
stack(req, resp).then(result=>assert.equal(result, 1));

API

compose(middlewares, options). options have:

  • beforeRunMiddleware: before invoking the specified middleware, check whether it can be run

License

Licensed under MIT

Copyright (c) 2017 Tian Jian

Readme

Keywords

Package Sidebar

Install

npm i midd-compose

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • kiliwalk
  • tianjianchn