{"id":13441606,"url":"https://github.com/ForbesLindesay/throat","last_synced_at":"2025-03-20T12:31:47.291Z","repository":{"id":6047556,"uuid":"7272353","full_name":"ForbesLindesay/throat","owner":"ForbesLindesay","description":"Throttle a collection of promise returning functions","archived":false,"fork":false,"pushed_at":"2023-01-03T13:31:48.000Z","size":87,"stargazers_count":484,"open_issues_count":13,"forks_count":40,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-19T13:57:14.743Z","etag":null,"topics":["concurrency","flow","promise","typescript"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Infinidat/jquery-treetable","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ForbesLindesay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null},"funding":{"github":["ForbesLindesay"],"patreon":"ForbesLindesay","open_collective":null,"ko_fi":null,"tidelift":"npm/throat","community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2012-12-21T10:58:14.000Z","updated_at":"2024-09-25T09:11:57.000Z","dependencies_parsed_at":"2023-01-13T13:48:44.346Z","dependency_job_id":null,"html_url":"https://github.com/ForbesLindesay/throat","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ForbesLindesay%2Fthroat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ForbesLindesay%2Fthroat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ForbesLindesay%2Fthroat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ForbesLindesay%2Fthroat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ForbesLindesay","download_url":"https://codeload.github.com/ForbesLindesay/throat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221435652,"owners_count":16820704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["concurrency","flow","promise","typescript"],"created_at":"2024-07-31T03:01:35.986Z","updated_at":"2024-10-28T01:31:33.897Z","avatar_url":"https://github.com/ForbesLindesay.png","language":"JavaScript","funding_links":["https://github.com/sponsors/ForbesLindesay","https://patreon.com/ForbesLindesay","https://tidelift.com/funding/github/npm/throat","https://tidelift.com/subscription/pkg/npm-throat?utm_source=npm-throat\u0026utm_medium=referral\u0026utm_campaign=readme","https://tidelift.com/security"],"categories":["HarmonyOS","JavaScript"],"sub_categories":["Windows Manager"],"readme":"# throat\n\nThrottle 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.\n\n[Professionally supported throat is now available](https://tidelift.com/subscription/pkg/npm-throat?utm_source=npm-throat\u0026utm_medium=referral\u0026utm_campaign=readme)\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/ForbesLindesay/throat/test.yml?branch=master\u0026style=for-the-badge)](https://github.com/ForbesLindesay/throat/actions/workflows/test.yml?query=branch%3Amaster)\n[![Coveralls github branch](https://img.shields.io/coveralls/github/ForbesLindesay/throat/master?color=brightgreen\u0026style=for-the-badge)](https://coveralls.io/github/ForbesLindesay/throat)\n[![Rolling Versions](https://img.shields.io/badge/Rolling%20Versions-Enabled-brightgreen?style=for-the-badge)](https://rollingversions.com/ForbesLindesay/throat)\n[![NPM version](https://img.shields.io/npm/v/throat?style=for-the-badge)](https://www.npmjs.com/package/throat)\n\n## Installation\n\n    npm install throat\n\n## API\n\n### throat(concurrency)\n\nThis returns a function that acts a bit like a lock (exactly as a lock if concurrency is 1).\n\nExample, only 2 of the following functions will execute at any one time:\n\n```js\nconst throat = require('throat')(2);\n\nconst resA = throat(async () =\u003e {\n  /* async stuff... */\n});\nconst resB = throat(async () =\u003e {\n  /* async stuff... */\n});\nconst resC = throat(async () =\u003e {\n  /* async stuff... */\n});\nconst resD = throat(async () =\u003e {\n  /* async stuff... */\n});\nconst resE = throat(async () =\u003e {\n  /* async stuff... */\n});\n```\n\n### throat(concurrency, worker)\n\nThis 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:\n\n```js\nconst throat = require('throat');\n\nconst input = ['fileA.txt', 'fileB.txt', 'fileC.txt', 'fileD.txt'];\nconst data = Promise.all(\n  input.map(throat(2, (fileName) =\u003e readFile(fileName)))\n);\n```\n\nOnly 2 files will be read at a time, sometimes limiting parallelism in this way can improve scalability.\n\n## Security contact information\n\nTo report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FForbesLindesay%2Fthroat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FForbesLindesay%2Fthroat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FForbesLindesay%2Fthroat/lists"}