{"id":16487405,"url":"https://github.com/tjenkinson/exponential-rate-limit","last_synced_at":"2025-03-23T12:33:52.074Z","repository":{"id":34301214,"uuid":"176120799","full_name":"tjenkinson/exponential-rate-limit","owner":"tjenkinson","description":"A small library which handles decaying exponential backoff. This is useful if you want to start throttling something whilst it is going wrong, but recover once things start working again.","archived":false,"fork":false,"pushed_at":"2024-03-29T19:25:24.000Z","size":562,"stargazers_count":3,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-12T13:34:03.918Z","etag":null,"topics":["backoff","decay","delay","exponential","exponential-backoff","retry","typescript"],"latest_commit_sha":null,"homepage":"https://exponential-rate-limit.netlify.com/demo.html","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tjenkinson.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-03-17T15:27:26.000Z","updated_at":"2023-03-04T17:50:42.000Z","dependencies_parsed_at":"2023-02-11T03:15:45.322Z","dependency_job_id":null,"html_url":"https://github.com/tjenkinson/exponential-rate-limit","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjenkinson%2Fexponential-rate-limit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjenkinson%2Fexponential-rate-limit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjenkinson%2Fexponential-rate-limit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjenkinson%2Fexponential-rate-limit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tjenkinson","download_url":"https://codeload.github.com/tjenkinson/exponential-rate-limit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221851005,"owners_count":16891699,"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":["backoff","decay","delay","exponential","exponential-backoff","retry","typescript"],"created_at":"2024-10-11T13:34:07.285Z","updated_at":"2024-10-28T15:50:41.874Z","avatar_url":"https://github.com/tjenkinson.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/exponential-rate-limit.svg)](https://badge.fury.io/js/exponential-rate-limit)\n# Exponential Rate Limit\nA small library which handles decaying exponential backoff. This is useful if you want to start throttling something whilst it is going wrong, but recover once things start working again.\n\n## Demo\nThe demo source is in \"[demo.ts](/src/demo.ts)\".\n\nTo run the demo locally run `npm run start`.\n\nIt is also hosted [here](https://exponential-rate-limit.netlify.com/demo.html) (thanks to [Netify](https://www.netlify.com/)).\n\n## Usage\n```ts\nimport { JobQueue, defaultDelayFunction } from './exponential-rate-limit';\n\nconst queue = new JobQueue({\n  /**\n   * The maximum time (seconds) between jobs executing.\n   */\n  maxInterval: 5\n  /**\n   * The delay function.\n   */\n  delayFunction: defaultDelayFunction\n});\n\nconst { remove } = queue.enqueue(({ enqueueTime } =\u003e {\n  console.log('Executing', enqueueTime);\n});\n```\n\n## Example\nThe following example implements `throttledFetch`, which will start delaying future executions exponentially (up to the default 5 seconds) every time a request fails or does not respond with status 200.\n\nEvery time there is a 200 response, the delays will also start getting shorter again. As time passes without any jobs being executed, the delay the next job would incur also decreases.\n\n```ts\nimport { JobQueue } from './exponential-rate-limit';\n\nconst jobQueue = new JobQueue(); // default options\n\nfunction throttledFetch(...fetchArgs): Promise\u003cResponse\u003e {\n  return new Promise((resolve) =\u003e {\n    jobQueue.enqueue(() =\u003e {\n      const fetchPromise = fetch(...fetchArgs);\n      resolve(fetchPromise);\n      return fetchPromise.then((response) =\u003e response.status === 200);\n    });\n  });\n}\n```\n\n## Browser\nThis can also be used in the browser thanks to [jsDelivr](https://github.com/jsdelivr/jsdelivr):\n```html\n\u003chead\u003e\n  \u003cscript type=\"text/javascript\" src=\"https://cdn.jsdelivr.net/npm/exponential-rate-limit@1\"\u003e\u003c/script\u003e\n  \u003cscript type=\"text/javascript\"\u003e\n    var queue = new ExponentialRateLimit.JobQueue();\n  \u003c/script\u003e\n\u003c/head\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjenkinson%2Fexponential-rate-limit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftjenkinson%2Fexponential-rate-limit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjenkinson%2Fexponential-rate-limit/lists"}