Middleware composition utility for Bay.
Like koa-compose@2
, but:
- returns the final value.
- supports async function.
next
is a yieldable function, e.g.yield * next
equalsyield * next()
.
npm i bay-compose
const compose = require('bay-compose')
compose([
function * (next) {
yield next
},
function * (next) {
yield next()
},
function * (next) {
yield * next
},
function * (next) {
yield * next()
},
async function (next) {
await next()
},
function (next) {
next().then(doSomeJob)
}
])(context)