mware-async is an extension to mware but for an async/await style middleware stack.
import mware from 'mware-async';
const { use, run } = mware();
const context = {};
// add middleware
use(async (ctx, next) => {
console.assert(ctx === context);
console.log('a');
await next();
console.log('b');
});
use(async (ctx, next) => {
console.log('c');
await next();
});
// run stack
run(context).then(() => console.log('fin')); // a, c, b, fin// error middleware
use(async () => throw new Error('Bad stuff!'));
// run
run().catch(err => console.error(err)); // [Error: Bad stuff!]npm install --save mware-async
yarn add mware-async
Returns a mware instance.
fn: Function|[]Function, Async middleware functions to add to stack.
args: *, Arguments to pass to each middleware function.
Returns a promise.
Copyright (c) 2016 9Technology