sequencing
v1.0.3
Published
Generic middleware pattern for sequential operations.
Downloads
4
Maintainers
Readme
Sequencing
Sequencing is a generic middleware pattern for sequential operations.
Install
npm i sequencing
Example
const createSeq = require('sequencing')
const seq = createSeq()
// set up middleware logic
seq.use((context, next) => {
console.log(context) // {name: 'Julie'}
next(null, { name: 'Jacob' }) // can change the context of the next middleware
})
seq.use((context, next) => {
console.log(context) // {name: 'Jacob'}
next(new Error('uh oh'), context) // set error
})
seq.useOnError((err, context) => {
console.log(err) // [Error: uh oh]
console.log(context) // {name: 'Jacob'}
})
// trigger an event for middleware to process
seq.fire({ name: 'Julie' })