倒退
简单的异步中间件模式。
安装
npm install throwback --save
用法
组成异步(返回承诺)功能。
const { compose } = require ( "throwback" ) ;
const fn = compose ( [
async function ( ctx , next ) {
console . log ( 1 ) ;
try {
await next ( ) ;
} catch ( err ) {
console . log ( "throwback" , err ) ;
}
console . log ( 4 ) ;
} ,
async function ( ctx , next ) {
console . log ( 2 ) ;
return next ( ) ;
}
] ) ;
// Callback runs at the end of the stack, before
// the middleware bubbles b