sequencing

1.0.3 • Public • Published

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' })

Package Sidebar

Install

npm i sequencing

Weekly Downloads

0

Version

1.0.3

License

none

Unpacked Size

4.32 kB

Total Files

4

Last publish

Collaborators

  • davidchubbs