Throwback
An asynchronous middleware pattern.
Installation
npm install throwback --save
Usage
Compose asynchronous functions (promise-based)
import { compose } from 'throwback'
const fn = compose([
async function (req, res, next) {
console.log(1)
try {
await next()
} catch (err) {
console.log('throwback', err)
}
console.log(4)
},
async function (req, res, next) {
console.log(2)
return next()
}
])
fn({}, {}, function (req, res) {
console.log(3)
res.status = 404
})
Inspiration
Built for popsicle
and inspired by koa-compose
.
License
MIT