JSPM

limit-concurrency-decorator

0.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 653
  • Score
    100M100P100Q110475F
  • License ISC

Decorator to limit concurrency of async functions

Package Exports

  • limit-concurrency-decorator

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (limit-concurrency-decorator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

limit-concurrency-decorator Build Status

Decorator to limit concurrency of async functions

Similar to these libraries, but can be used as decorator:

Also similar to p-concurrency, but the limit can be enforced over multiple functions.

Install

Installation of the npm package:

> npm install --save limit-concurrency-decorator

Usage

Simply apply the decorator to a method:

import limit from 'limit-concurrency-decorator'

class HttpClient {
  @limit(2)
  get () {
    // ...
  }
}

const client = new HttpClient()

// these calls will run in parallel
client.get('http://example.net/')
client.get('http://example2.net/')

// this call will wait for the 2 previous to finish
client.get('http://example3.net/')

Or a simple function as a wrapper:

import httpRequest from 'http-request-plus'

const httpRequestLimited = limit(2)(httpRequest)

// these calls will run in parallel
httpRequestLimited('http://example.net/')
httpRequestLimited('http://example2.net/')

// this call will wait for the 2 previous to finish
httpRequestLimited('http://example3.net/')

The limit can be shared:

const myLimit = limit(2)

class HttpClient {
  @myLimit
  post () {
    // ...
  }

  @myLimit
  put () {
    // ...
  }
}

Development

# Install dependencies
> npm install

# Run the tests
> npm test

# Continuously compile
> npm run dev

# Continuously run the tests
> npm run dev-test

# Build for production (automatically called by npm install)
> npm run build

Contributions

Contributions are very welcomed, either on the documentation or on the code.

You may:

  • report any issue you've encountered;
  • fork and create a pull request.

License

ISC © Julien Fontanet