6.0.2 • Published 2 years ago

throat v6.0.2

Weekly downloads
11,177,621
License
MIT
Repository
github
Last release
2 years ago

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

@orillusion/jest-electronarchetype-libraryeasy-select-rnreact-native-bluetooth2killi8n-react-native-fast-imagern-send-smsspecify-importsbabel-specify-imports@icanpm/api-masterreact-native-template-rfbaseairscanairscan-exampleyy-jest-electronreact-native-esc-pos-sahaab@borisovart/atol-kkt-module@squidjs/jest-electrondeneme323112sitemap-cli-tools@ntt_app/react-native-custom-notificationreact-native-custom-text-hwjamesreact-native-covid-sdkgql_din_modbitgetreact-native-thanh-toast-library@thanhnguyen14797/react-native-thanh-toast-library@olivervorasai/sliderreact-native-printer-brothersrn-pdf-reader-offlinereact-native-shekhar-bridge-testwilscanner@oiti/documentoscopy-react-nativejest-hax-electronjest-electrochrome@mink-opn/build-tokensquoc-testrn-0.45-fork-oreoreact-native-slider-kfunblock-block-save-variableselectrochrome@infinitebrahmanuniverse/nolb-throplginexpand-react-bridgeluminos-ui-coresklif-ui-kitsklif-api@everything-registry/sub-chunk-2940jawwy-sdkjawwy_gamification_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgp149-tablesklif-uireact-native-jawwy_samplegriffin-ui-librarytaxi-ranktailwind-vector-effectsyncbackbasestest-library-123test-haptik-libtest-npm-jjmessiwonder-jest-runnerwebchewoven-challenge-deploywifi_configuration_packagewsrunwsrun-ngrunnercamp-react-natives3-asset-uploadrn-tm-notifyrn-use-modal-hookrn-currency-formatterrn-counter-demorn-session-multiplier-demorn_unique_device_idrnttlocksharingcomponent2sauce-testscrapistschlumpshishirm-toolbox-linterresponsis-gantt-task-reactreport-missing-dependenciesresponsive-react-appreactnativelyreactofy-css-libraryreikamoon-string-library-aarfp-librn-check-btnrn-circular-chartrn-horizontal-listreact_native_pandey_marqueerocket-bundlerrelax-mjrn-adyen-dropinrn-keyboard-avoiding-viewrn-my-libraryrn-pay-sdkrn-packager
6.0.2

2 years ago

6.0.1

4 years ago

6.0.0

4 years ago

5.0.0

6 years ago

4.1.0

8 years ago

4.0.0

8 years ago

3.2.0

8 years ago

3.1.0

8 years ago

3.0.0

9 years ago

2.0.2

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.0.0

12 years ago

0.0.0

12 years ago