{"id":13459118,"url":"https://github.com/sindresorhus/p-limit","last_synced_at":"2025-05-13T17:03:25.951Z","repository":{"id":37502488,"uuid":"71542716","full_name":"sindresorhus/p-limit","owner":"sindresorhus","description":"Run multiple promise-returning \u0026 async functions with limited concurrency","archived":false,"fork":false,"pushed_at":"2024-12-19T15:46:45.000Z","size":37,"stargazers_count":2312,"open_issues_count":6,"forks_count":115,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-05-05T22:53:35.042Z","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/sindresorhus.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":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2016-10-21T07:51:54.000Z","updated_at":"2025-05-04T21:19:54.000Z","dependencies_parsed_at":"2024-01-13T10:40:03.780Z","dependency_job_id":"b5308556-90ca-45c4-811f-aa71b8b30539","html_url":"https://github.com/sindresorhus/p-limit","commit_stats":{"total_commits":54,"total_committers":15,"mean_commits":3.6,"dds":0.2777777777777778,"last_synced_commit":"c7f7687dba1ecd52ef884fff29cab716ce4becc7"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-limit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-limit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-limit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fp-limit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/p-limit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252590532,"owners_count":21772935,"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-07-31T09:01:05.013Z","updated_at":"2025-05-05T22:53:40.251Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["JavaScript","Packages","others","Uncategorized","Convenience Utilities"],"sub_categories":["Uncategorized","sindresorhus's many Promise utilities ([see notes](https://github.com/sindresorhus/promise-fun))","sindresorhus's many Promise utilities (\u003cb\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;5146⭐\u003c/code\u003e\u003c/b\u003e \u003cb\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;138🍴\u003c/code\u003e\u003c/b\u003e [see notes](https://github.com/sindresorhus/promise-fun)))"],"readme":"# p-limit\n\n\u003e Run multiple promise-returning \u0026 async functions with limited concurrency\n\n*Works in Node.js and browsers.*\n\n## Install\n\n```sh\nnpm install p-limit\n```\n\n## Usage\n\n```js\nimport pLimit from 'p-limit';\n\nconst limit = pLimit(1);\n\nconst input = [\n\tlimit(() =\u003e fetchSomething('foo')),\n\tlimit(() =\u003e fetchSomething('bar')),\n\tlimit(() =\u003e doSomething())\n];\n\n// Only one promise is run at once\nconst result = await Promise.all(input);\nconsole.log(result);\n```\n\n## API\n\n### pLimit(concurrency) \u003csup\u003edefault export\u003c/sup\u003e\n\nReturns a `limit` function.\n\n#### concurrency\n\nType: `number`\\\nMinimum: `1`\n\nConcurrency limit.\n\n### limit(fn, ...args)\n\nReturns the promise returned by calling `fn(...args)`.\n\n#### fn\n\nType: `Function`\n\nPromise-returning/async function.\n\n#### args\n\nAny arguments to pass through to `fn`.\n\nSupport for passing arguments on to the `fn` is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a *lot* of functions.\n\n### limit.activeCount\n\nThe number of promises that are currently running.\n\n### limit.pendingCount\n\nThe number of promises that are waiting to run (i.e. their internal `fn` was not called yet).\n\n### limit.clearQueue()\n\nDiscard pending promises that are waiting to run.\n\nThis might be useful if you want to teardown the queue at the end of your program's lifecycle or discard any function calls referencing an intermediary state of your app.\n\nNote: This does not cancel promises that are already running.\n\n### limit.concurrency\n\nGet or set the concurrency limit.\n\n### limitFunction(fn, options) \u003csup\u003enamed export\u003c/sup\u003e\n\nReturns a function with limited concurrency.\n\nThe returned function manages its own concurrent executions, allowing you to call it multiple times without exceeding the specified concurrency limit.\n\nIdeal for scenarios where you need to control the number of simultaneous executions of a single function, rather than managing concurrency across multiple functions.\n\n```js\nimport {limitFunction} from 'p-limit';\n\nconst limitedFunction = limitFunction(async () =\u003e {\n\treturn doSomething();\n}, {concurrency: 1});\n\nconst input = Array.from({length: 10}, limitedFunction);\n\n// Only one promise is run at once.\nawait Promise.all(input);\n```\n\n#### fn\n\nType: `Function`\n\nPromise-returning/async function.\n\n#### options\n\nType: `object`\n\n#### concurrency\n\nType: `number`\\\nMinimum: `1`\n\nConcurrency limit.\n\n## FAQ\n\n### How is this different from the [`p-queue`](https://github.com/sindresorhus/p-queue) package?\n\nThis package is only about limiting the number of concurrent executions, while `p-queue` is a fully featured queue implementation with lots of different options, introspection, and ability to pause the queue.\n\n## Related\n\n- [p-throttle](https://github.com/sindresorhus/p-throttle) - Throttle promise-returning \u0026 async functions\n- [p-debounce](https://github.com/sindresorhus/p-debounce) - Debounce promise-returning \u0026 async functions\n- [p-all](https://github.com/sindresorhus/p-all) - Run promise-returning \u0026 async functions concurrently with optional limited concurrency\n- [More…](https://github.com/sindresorhus/promise-fun)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fp-limit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fp-limit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fp-limit/lists"}