{"id":22382359,"url":"https://github.com/jcoreio/async-throttle","last_synced_at":"2025-07-15T21:42:31.147Z","repository":{"id":20028619,"uuid":"88570976","full_name":"jcoreio/async-throttle","owner":"jcoreio","description":"throttle async and promise-returning functions like lodash.throttle","archived":false,"fork":false,"pushed_at":"2024-10-08T14:11:12.000Z","size":2015,"stargazers_count":21,"open_issues_count":17,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T09:01:45.260Z","etag":null,"topics":["async","async-await","promise","throttle"],"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/jcoreio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2017-04-18T02:12:11.000Z","updated_at":"2024-11-30T13:46:21.000Z","dependencies_parsed_at":"2024-06-18T18:59:27.345Z","dependency_job_id":"d0cb6669-f419-4371-9b3d-e9e2aca5392b","html_url":"https://github.com/jcoreio/async-throttle","commit_stats":{"total_commits":254,"total_committers":5,"mean_commits":50.8,"dds":0.1692913385826772,"last_synced_commit":"74a28ffe88f1b6191d2eb35d623769d4e9c6bc27"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fasync-throttle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fasync-throttle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fasync-throttle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fasync-throttle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcoreio","download_url":"https://codeload.github.com/jcoreio/async-throttle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675352,"owners_count":21143763,"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":["async","async-await","promise","throttle"],"created_at":"2024-12-05T00:12:41.890Z","updated_at":"2025-07-15T21:42:31.136Z","avatar_url":"https://github.com/jcoreio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# async-throttle\n\n[![CircleCI](https://circleci.com/gh/jcoreio/async-throttle.svg?style=svg)](https://circleci.com/gh/jcoreio/async-throttle)\n[![codecov](https://codecov.io/gh/jcoreio/async-throttle/branch/master/graph/badge.svg?token=pLauOb4sn7)](undefined)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![npm version](https://badge.fury.io/js/%40jcoreio%2Fasync-throttle.svg)](https://badge.fury.io/js/%40jcoreio%2Fasync-throttle)\n\nThrottle async and promise returning functions. Unlike similarly named packages, this behaves much like an async version of\n[`lodash.throttle`](https://lodash.com/docs/4.17.15#throttle):\n\n- Only one invocation can be running at a time (similarly named packages don't do this)\n- Has `.cancel()` and `.flush()`\n\n## Differences from `lodash.throttle`\n\n- No `leading` and `trailing` options (they're both always `true`)\n- `getNextArgs` option allows you to customize how the arguments for the next invocation are determined\n\n## Installing\n\n```sh\nnpm install --save @jcoreio/async-throttle\n```\n\n### Usage\n\n```js\nconst throttle = require('@jcoreio/async-throttle')\nimport throttle from '@jcoreio/async-throttle'\n```\n\n```js\nfunction throttle\u003cArgs: Array\u003cany\u003e, Value\u003e(\n  func: (...args: Args) =\u003e Promise\u003cValue\u003e,\n  wait: ?number,\n  options?: {\n    getNextArgs?: (current: Args, next: Args) =\u003e Args\n  }\n): (...args: Args) =\u003e Promise\u003cValue\u003e;\n```\n\nCreates a throttled function that only invokes `func` at most once per every `wait` milliseconds, and also waits for the\n`Promise` returned by the previous invocation to finish (it won't invoke `func` in parallel).\n\nThe promise returned by the throttled function will track the promise returned by the next invocation of `func`.\n\nIf `wait` is falsy, it is treated as 0, which causes `func` to be invoked on the next tick afte the previous invocation\nfinishes.\n\nBy default, `func` is called with the most recent arguments to the throttled function. You can change this with the\n`getNextArgs` option -- for example, if you want to invoke `func` with the minimum of all arguments since the last\ninvocation:\n\n```js\nconst throttledFn = throttle(foo, 10, {\n  getNextArgs: ([a], [b]) =\u003e [Math.min(a, b)],\n})\nthrottledFn(2)\nthrottledFn(1)\nthrottledFn(3)\n// foo will be called with 1\n\n// time passes...\n\nthrottledFn(4)\nthrottledFn(6)\nthrottledFn(5)\n// foo will be called with 4\n```\n\n### `throttledFn.invokeIgnoreResult(args)`\n\nCalls the throttled function soon, but doesn't return a promise, catches any CanceledError, and doesn't create any new promises if a call is already pending.\n\nTo use this, you should handle all errors inside the throttled function:\n\n```js\nconst throttled = throttle(async (arg) =\u003e {\n  try {\n    await doSomething(arg)\n  } catch (err) {\n    // handle error\n  }\n})\n```\n\nThen call `invokeIgnoreResult` instead of the throttled function:\n\n```js\nthrottled.invokeIgnoreResult(arg)\n```\n\nThe `invokeIgnoreResult` method is useful because the following code example would leave 1000 pending promises\non the heap, even though the catch block is a no-op:\n\n```js\nfor (let i = 0; i \u003c 1000; i++) {\n  throttled(arg).catch(() =\u003e {})\n}\n```\n\n### `throttledFn.cancel()`\n\nCancels the pending invocation, if any. All `Promise`s tracking the pending invocation will be\nrejected with a `CancelationError` (`const {CancelationError} = require('@jcoreio/async-throttle')`).\nHowever, if an invocation is currently running, all `Promise`s tracking the current invocation will be fulfilled as usual.\n\nReturns a `Promise` that will resolve once the current invocation (if any) is finished.\n\n### `throttledFn.flush()`\n\nCancels the `wait` before the pending invocation, if any. The pending invocation will still wait for the current invocation (if any)\nto finish, but will begin immediately afterward, even if `wait` has not elapsed.\n\nReturns a `Promise` that will resolve once the current invocation (if any) is finished.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fasync-throttle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcoreio%2Fasync-throttle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fasync-throttle/lists"}