Socket
Socket
Sign inDemoInstall

async-ware

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    async-ware

A class for easily writing js middlewares


Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Install size
4.42 kB
Created
Weekly downloads
 

Readme

Source

async-ware

NPM version Build status Test coverage License

The programming idea(🧅 onion model) of koa middleware is great, it can be applied to more situations.

We need one class to include that all, so here comes this lib

  • ✅ use it in one class(no need to include koa), see code example below
  • ✅ variadic arguments for the whole running
  • ✅ catch the error by ware.run() 's promise

How to use

Install

npm i async-ware -S

Example

const Middleware = require('async-ware')

const ware = new Middleware()

ware.use(async (a, b, next) => {
  console.log('middleware 1a ***', ++a.a, a)
  await next()
  console.log('middleware 1b ***', ++b.b, b)
})

ware.use(async (a, b, next) => {
  console.log('middleware 2a ***', ++a.a, a)
  await sleep(200)
  await next()
  await sleep(300)
  console.log('middleware 2b ***', ++b.b, b)
})

ware.use(async (a, b, next) => {
  console.log('middleware 3a ***', ++a.a, a)
  await sleep(400)
  await next()
  await sleep(500)
  console.log('middleware 3b ***', ++b.b, b)
})

// The middlewares above, function's arguments a and b is the `run` function's arguments
// You can use variadic arguments here
ware.run({ a: 10 }, { b: 20 })
  .then(console.log)
  .catch(console.error)

License

MIT

Keywords

FAQs

Last updated on 30 Jun 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc