{"id":16920687,"url":"https://github.com/dherault/throttle-asynchronous","last_synced_at":"2026-05-18T08:05:37.588Z","repository":{"id":35885996,"uuid":"219706697","full_name":"dherault/throttle-asynchronous","owner":"dherault","description":"Throttle many promises, resolve once.","archived":false,"fork":false,"pushed_at":"2023-01-09T17:14:53.000Z","size":389,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-26T07:48:54.853Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/dherault.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}},"created_at":"2019-11-05T09:29:54.000Z","updated_at":"2023-03-31T14:51:57.000Z","dependencies_parsed_at":"2023-01-16T08:37:33.743Z","dependency_job_id":null,"html_url":"https://github.com/dherault/throttle-asynchronous","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dherault%2Fthrottle-asynchronous","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dherault%2Fthrottle-asynchronous/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dherault%2Fthrottle-asynchronous/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dherault%2Fthrottle-asynchronous/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dherault","download_url":"https://codeload.github.com/dherault/throttle-asynchronous/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244717339,"owners_count":20498283,"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-10-13T19:49:11.032Z","updated_at":"2026-05-18T08:05:32.557Z","avatar_url":"https://github.com/dherault.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# throttle-asynchronous\n\n[![npm version](https://badge.fury.io/js/throttle-asynchronous.svg)](https://badge.fury.io/js/throttle-asynchronous)\n\nThrottle many promises, resolve once.\n\n## Installation\n\n`npm install throttle-asynchronous --save`\n\nor\n\n`yard add throttle-asynchronous`\n\n## Usage\n\n```js\nimport throttle from 'throttle-asynchronous'\n\nconst throttledFn = throttle(asyncFn, duration)\n\nconst { hasResolved, value } = await throttledFn(argsForAsyncFn)\n```\n\nThen you can call your throttled function in a batch:\n\n```js\nthrottledFn(args) // promise: { hasResolved: false } Did not resolve because a sibling was invoked in the interval duration\nthrottledFn(args) // promise: { hasResolved: false }\nthrottledFn(args) // promise: { hasResolved: true, value: ... } Resolved because last in the batch\n```\n\nWorks with synchronous functions too.\n\n## Example\n\n```js\nimport throttle from 'throttle-asynchronous'\n\n// This function will be throttled to update only once per 1 second batch\nfunction updateStory(text) {\n  return database.stories.update('storyId', { text })\n}\n\n// If launched at an interval below 1000ms, only the last throttledUpdateStory will execute\nconst throttledUpdateStory = throttle(updateStory, 1000)\n\n// Each keystroke will trigger input.onChange, hence the throttle\ninput.onChange = async text =\u003e {\n  setState({ updated: false })\n\n  const { hasResolved, value } = await throttledUpdateStory(text)\n\n  if (hasResolved) {\n    setState({ updated: true })\n\n    console.log('response from database:', value)\n  }\n}\n```\n\n## Say thanks\n\nShow your gratitude with a star on [GitHub](https://github.com/dherault/throttle-asynchronous)!\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdherault%2Fthrottle-asynchronous","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdherault%2Fthrottle-asynchronous","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdherault%2Fthrottle-asynchronous/lists"}