6.0.2 • Published 1 year ago

throat v6.0.2

Weekly downloads
11,177,621
License
MIT
Repository
github
Last release
1 year 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_sample@corelmax/react-native-my2c2p-sdk@damruravihara/react-native-testing-package@damian.lnc/core@cqingwang/react-native@crazyfactory/webp-converter-cli@crazyfactory/jpeg-compression-cli@crazyfactory/png-compression-cli@deep27/supersetpluginchart-helloworld@cryptocode99/token-lists@cs6/react-native-test-native-view-library@con-test/react-native-concent-common@idas1/ui-component-libcnpm-check@hypersprite/jest-runner-electron@innoq/fractal-forkconway-game@innodata/vue-v3-ya-metrikacaravancarrack@hawkingnetwork/react-native-tab-viewcapacitor-bluetooth-lecapacitor-bluetooth-le-long-timeouts@gzup/react-image-file-resizer@hlolli/create-jest-runner@brantalikp/rn-resize@cdk8s-extensions/argo-rollout@chrisyang/electron@garonx/oracle-zkapp@furgot100/dates-lib@furgot100/string-lib@globality/nodule-openapi@iyansr/react-native-image-viewing@jasonmit/ember-cli-deploy-sentrycpcs6_logger@janiscommerce/serverless-plugin-split-stacks@inti-ar/evm-chainsdepensitor@maujzs/branch-release@massivepixel/use-querydate-library-aadate_operations_manipulatorcreate-jest-runner-with-skip@johanblumenberg/wsrun@meysam213/react-leaflet@ndn/repo
6.0.2

1 year ago

6.0.1

3 years ago

6.0.0

3 years ago

5.0.0

5 years ago

4.1.0

7 years ago

4.0.0

7 years ago

3.2.0

7 years ago

3.1.0

7 years ago

3.0.0

8 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.0

11 years ago

0.0.0

11 years ago