{"id":21182811,"url":"https://github.com/seriousbug/live-limit","last_synced_at":"2025-07-10T00:32:50.916Z","repository":{"id":82539253,"uuid":"499912217","full_name":"SeriousBug/live-limit","owner":"SeriousBug","description":"A promise based generic rate limiter. Runs a limited number of async function calls at a time, queuing or discarding remaining calls.","archived":false,"fork":false,"pushed_at":"2023-04-17T23:40:52.000Z","size":330,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-01T23:38:31.889Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/SeriousBug.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-04T18:55:59.000Z","updated_at":"2024-04-19T06:06:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"d0be0ad1-b329-4379-911b-256047483b78","html_url":"https://github.com/SeriousBug/live-limit","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.0357142857142857,"last_synced_commit":"887bf3166f79751d3ea2588b5b371246825f6614"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":"codex-team/typescript-lib-template","purl":"pkg:github/SeriousBug/live-limit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeriousBug%2Flive-limit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeriousBug%2Flive-limit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeriousBug%2Flive-limit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeriousBug%2Flive-limit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SeriousBug","download_url":"https://codeload.github.com/SeriousBug/live-limit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeriousBug%2Flive-limit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264506220,"owners_count":23619002,"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-11-20T17:58:11.705Z","updated_at":"2025-07-10T00:32:50.901Z","avatar_url":"https://github.com/SeriousBug.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Live Limit\n\n[![npm](https://img.shields.io/npm/v/live-limit)](https://www.npmjs.com/package/live-limit) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/live-limit)](https://bundlephobia.com/package/live-limit@1.0.0) [![coverage badge](https://img.shields.io/codecov/c/github/SeriousBug/live-limit)](https://app.codecov.io/gh/SeriousBug/live-limit) [![tests badge](https://img.shields.io/github/actions/workflow/status/SeriousBug/live-limit/test.yml?label=tests\u0026branch=main)](https://github.com/SeriousBug/live-limit/actions/workflows/test.yml) [![0 dependencies](https://img.shields.io/badge/dependencies-0-success)](https://www.npmjs.com/package/live-limit) [![MIT license](https://img.shields.io/npm/l/live-limit)](https://github.com/SeriousBug/live-limit/blob/main/LICENSE)\n\nNeed to limit the number of concurrent requests to a server? Or make sure only one function call is running at a time?\nLive Limit to the rescue!\n\n## Docs\n\nSee the [Live Limit Docs](https://seriousbug.github.io/live-limit/) for details.\n\n## Install\n\n```sh\n# with npm\nnpm install --save live-limit\n# with yarn\nyarn add live-limit\n```\n\n#### Requirements\n\nLive Limit requires [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#browser_compatibility) and [`Map.values`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values#browser_compatibility). This is available on everything newer than node.js 12 and any non-IE browser.\n\nIf Internet Explorer support is required, consider polyfills.\n\n## Example\n\n```ts\nimport { LiveLimit } from \"live-limit\";\n\n// Setup\n// Only allows 3 function calls to be live at a time\nconst LIMITER = new LiveLimit({ maxLive: 3 });\n\n// Making a single call:\nconst param = 1;\nLIMITER.limit(async () =\u003e {\n    // code here\n});\n\n// Making many calls:\n//\n// With these limiter settings, the first 3 calls will start immediately.\n// The next 3 will pause until one of the earlier calls resolve or reject,\n// at which point another call will start.\nconst params = [1, 2, 3, 4, 5, 6];\nparams.forEach((param) =\u003e {\n    LIMITER.limit(async () =\u003e {\n        myFunc(param);\n    });\n});\n\n// The async calls can also return a result.\n// The promise returned by `LIMITER.limit` will be the result that your function returned.\nconst out = await LIMITER.limit(async () =\u003e {\n    return 'foo';\n});\nconsole.log(out); // prints 'foo'\n```\n\n### Example with Axios, React, and Redux\n\n```tsx\n// ... other imports\nimport { LiveLimit } from \"live-limit\";\n\n// 3 concurrent connections at max\nconst LIMITER = new LiveLimit({ maxLive: 3 });\n\nfunction SendButton() {\n    const dataToSend: any[] = selector((state) =\u003e state.data.to.send);\n    const [state, setState] = useState\u003c\"done\" | \"loading\" | undefined\u003e();\n\n    return (\n        \u003cButton\n            // Disable button while loading or done\n            disabled={state !== undefined}\n            // When clicked, make all the requests\n            onClick={() =\u003e {\n                // Disable the button\n                setState(\"loading\");\n                // Wait until it's done to mark as done\n                Promise.all(\n                    dataToSend.map(\n                        // Creating a promise for each request\n                        async (data) =\u003e {\n                            // Every request goes through the limiter\n                            await LIMITER.limit(async () =\u003e {\n                                await axios.post(\"/url/to/send/to\", data);\n                            });\n                        }\n                    )\n                ).then(() =\u003e {\n                    setState(\"done\");\n                });\n            }}\n        \u003e\n            Send all the data\n        \u003c/Button\u003e\n    );\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseriousbug%2Flive-limit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseriousbug%2Flive-limit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseriousbug%2Flive-limit/lists"}