0.1.1 • Published 9 years ago
mware-async v0.1.1
mware-async
mware-async is an extension to mware but for an async/await style middleware stack.
Usage
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, finErrors
// error middleware
use(async () => throw new Error('Bad stuff!'));
// run
run().catch(err => console.error(err)); // [Error: Bad stuff!]Installation
NPM
npm install --save mware-asyncYarn
yarn add mware-asyncAPI
mware()
Returns a mware instance.
Instance
#use(fn...)
fn: Function|[]Function, Async middleware functions to add to stack.
#run([...args])
args: *, Arguments to pass to each middleware function.
Returns a promise.
License
Copyright (c) 2016 9Technology