{"id":13826075,"url":"https://github.com/lukeed/throttles","last_synced_at":"2025-10-09T18:24:33.997Z","repository":{"id":65412398,"uuid":"203678323","full_name":"lukeed/throttles","owner":"lukeed","description":"A tiny (139B to 204B) utility to regulate the execution rate of your functions","archived":false,"fork":false,"pushed_at":"2023-08-14T20:24:21.000Z","size":18,"stargazers_count":198,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-30T18:52:33.005Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukeed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-08-21T23:21:52.000Z","updated_at":"2025-02-11T21:34:43.000Z","dependencies_parsed_at":"2024-01-18T04:07:14.049Z","dependency_job_id":"bb68defc-cb1e-47dc-bb11-cb9a558c24c7","html_url":"https://github.com/lukeed/throttles","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"40af81fb586642ceda58326cfac830b9bb9c9722"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/lukeed/throttles","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fthrottles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fthrottles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fthrottles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fthrottles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/throttles/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fthrottles/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264365424,"owners_count":23596824,"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":[],"created_at":"2024-08-04T09:01:31.740Z","updated_at":"2025-10-09T18:24:28.979Z","avatar_url":"https://github.com/lukeed.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# throttles [![build status](https://badgen.now.sh/github/status/lukeed/throttles)](https://github.com/lukeed/throttles/actions) [![codecov](https://badgen.now.sh/codecov/c/github/lukeed/throttles)](https://codecov.io/gh/lukeed/throttles)\n\n\u003e A tiny (139B to 204B) utility to regulate the execution rate of your functions\n\n\n## Install\n\n```\n$ npm install --save throttles\n```\n\n\n## Modes\n\nThere are two \"versions\" of `throttles`, each of which different purpose:\n\n#### \"single\"\n\u003e **Size (gzip):** 139 bytes\u003cbr\u003e\n\u003e **Availability:** [UMD](https://unpkg.com/throttles), [CommonJS](https://unpkg.com/throttles/dist/index.js), [ES Module](https://unpkg.com/throttles?module)\n\nThis is the primary/default mode, meant for managing single queues.\n\n#### \"priority\"\n\u003e **Size (gzip):** 204 bytes\u003cbr\u003e\n\u003e **Availability:** [UMD](https://unpkg.com/throttles/priority), [ES Module](https://unpkg.com/throttles/priority/index.mjs)\n\nThis is the opt-in mode, meant for managing a low priority _and_ a high priority queue system.\u003cbr\u003e\nItems within the \"high priority\" queue are handled before the low/general queue. The `limit` is still enforced.\n\n\n## Usage\n\n***Selecting a Mode***\n\n```js\n// import via npm module\nimport throttles from 'throttles';\nimport throttles from 'throttles/priority';\n\n// import via unpkg\nimport throttles from 'https://unpkg.com/throttles/index.mjs';\nimport throttles from 'https://unpkg.com/throttles/priority/index.mjs';\n```\n\n***Example Usage***\n\n```js\nimport throttles from 'throttles';\n\nconst API = 'https://pokeapi.co/api/v2/pokemon';\nconst getPokemon = id =\u003e fetch(`${API}/${id}`).then(r =\u003e r.json());\n\n// Limit concurrency to 3\nconst [toAdd, isDone] = throttles(3);\n\n// What we'll fetch\nconst pokemon = ['bulbasaur', 'ivysaur', 'venusaur', 'charmander', 'charmeleon', 'charizard', ...];\n\n// Loop list, enqueuing each Pokemon\n// ~\u003e Always keeps 3 requests active at a time\n// ~\u003e When complete, marks itself complete via `isDone()`\npokemon.forEach(name =\u003e {\n\ttoAdd(() =\u003e {\n\t\tgetPokemon(name).then(isDone);\n\t});\n});\n\n// Or, use `Array.map` to wrap our `getPokemon` function\n// ~\u003e This still fetches Pokemon 3 at once\npokemon.map(x =\u003e () =\u003e getPokemon(x).then(isDone)).forEach(toAdd);\n```\n\n\n## API\n\n### throttles(limit)\nReturns: `Array`\n\nReturns a tuple of [[`toAdd`](#toaddfn-ishigh), [`isDone`](#isdone)] actions.\n\n#### limit\nType: `Number`\u003cbr\u003e\nDefault: `1`\n\nThe throttle's concurrency limit. By default, runs your functions one at a time.\n\n\n### toAdd(fn[, isHigh])\nType: `Function`\u003cbr\u003e\nReturns: `void`\n\nAdd a function to the throttle's queue.\n\n\u003e **Important:** In \"priority\" mode, identical functions are ignored.\n\n#### fn\nType: `Function`\u003cbr\u003e\nThe function to add to the queue.\n\n#### isHigh\nType: `Boolean`\u003cbr\u003e\nDefault: `false`\u003cbr\u003e\nIf the `fn` should be added to the \"high priority\" queue.\n\n\u003e **Important:** Only available in \"priority\" mode!\n\n\n### isDone\nType: `Function`\u003cbr\u003e\nReturns: `void`\n\nSignifies that a function has been completed.\n\n\u003e **Important:** Failure to call this will prevent `throttles` from continuing to the next item!\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fthrottles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fthrottles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fthrottles/lists"}