Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

throat

Package Overview
Dependencies
0
Maintainers
2
Versions
13
Issues
File Explorer

Advanced tools

throat

Throttle the parallelism of an asynchronous (promise returning) function / functions

    6.0.1latest

Version published
Maintainers
2
Weekly downloads
15,249,300
decreased by-0.88%

Weekly downloads

Changelog

Source

6.0.1

Performance Improvements

  • Optimise the queue again (#57)

    6.0.0 was significantly slower than 5.0.0. This restores the balance. Each of these benchmarks is run 10x times, in order to make the numbers reasonably stable for comparison.

    5.0.0 benchmark:

    limit=10 10 promises: 1.118ms 100 promises: 31.778ms 1000 promises: 22.806ms 10000 promises: 59.501ms 100000 promises: 941.285ms 1000000 promises: 11.569s limit=1000000 10 promises: 0.177ms 100 promises: 0.425ms 1000 promises: 4.904ms 10000 promises: 84.251ms 100000 promises: 1.081s 1000000 promises: 13.656s

    6.0.0 benchmark:

    limit=10 10 promises: 1.122ms 100 promises: 18.4ms 1000 promises: 34.742ms 10000 promises: 86.504ms 100000 promises: 1.475s 1000000 promises: 20.298s limit=1000000 10 promises: 0.264ms 100 promises: 0.424ms 1000 promises: 5.6ms 10000 promises: 93.45ms 100000 promises: 1.466s 1000000 promises: 20.109s

    6.0.1 benchmark:

    limit=10 10 promises: 1.217ms 100 promises: 4.433ms 1000 promises: 49.928ms 10000 promises: 67.578ms 100000 promises: 958.481ms 1000000 promises: 10.542s limit=1000000 10 promises: 0.118ms 100 promises: 0.424ms 1000 promises: 4.993ms 10000 promises: 84.649ms 100000 promises: 1.163s 1000000 promises: 13.297s

Readme

Source

throat

Throttle the parallelism of an asynchronous, promise returning, function / functions. This has special utility when you set the concurrency to 1. That way you get a mutually exclusive lock.

Professionally supported throat is now available

Build Status Coveralls github branch Rolling Versions NPM version

Installation

npm install throat

API

throat(concurrency)

This returns a function that acts a bit like a lock (exactly as a lock if concurrency is 1).

Example, only 2 of the following functions will execute at any one time:

const throat = require('throat')(2); const resA = throat(async () => { /* async stuff... */ }); const resB = throat(async () => { /* async stuff... */ }); const resC = throat(async () => { /* async stuff... */ }); const resD = throat(async () => { /* async stuff... */ }); const resE = throat(async () => { /* async stuff... */ });

throat(concurrency, worker)

This returns a function that is an exact copy of worker except that it will only execute up to concurrency times in parallel before further requests are queued:

const throat = require('throat'); const input = ['fileA.txt', 'fileB.txt', 'fileC.txt', 'fileD.txt']; const data = Promise.all( input.map(throat(2, (fileName) => readFile(fileName))) );

Only 2 files will be read at a time, sometimes limiting parallelism in this way can improve scalability.

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

License

MIT

Keywords

FAQs

What is throat?

Throttle the parallelism of an asynchronous (promise returning) function / functions

Is throat popular?

The npm package throat receives a total of 13,291,778 weekly downloads. As such, throat popularity was classified as popular.

Is throat well maintained?

We found that throat demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 2 open source maintainers collaborating on the project.

Last updated on 20 Jan 2021

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc