{"id":23773355,"url":"https://github.com/beenotung/backoff-pool","last_synced_at":"2026-05-12T23:37:49.321Z","repository":{"id":63692094,"uuid":"569935923","full_name":"beenotung/backoff-pool","owner":"beenotung","description":"A helper library to manage expotential backoff intervals of different resources.  This can be used to manage retry interval of login attempts per IP address.","archived":false,"fork":false,"pushed_at":"2022-11-26T06:35:51.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-19T21:35:39.713Z","etag":null,"topics":["backoff","expotential","npm-package","pool-manager","rate-limiting","typescript-library"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/backoff-pool","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beenotung.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":"2022-11-24T00:44:07.000Z","updated_at":"2022-11-26T06:35:57.000Z","dependencies_parsed_at":"2023-01-23T00:16:08.271Z","dependency_job_id":null,"html_url":"https://github.com/beenotung/backoff-pool","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/beenotung/backoff-pool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Fbackoff-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Fbackoff-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Fbackoff-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Fbackoff-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beenotung","download_url":"https://codeload.github.com/beenotung/backoff-pool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beenotung%2Fbackoff-pool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279159536,"owners_count":26116492,"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","status":"online","status_checked_at":"2025-10-16T02:00:06.019Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","expotential","npm-package","pool-manager","rate-limiting","typescript-library"],"created_at":"2025-01-01T05:39:23.422Z","updated_at":"2025-10-16T05:29:23.482Z","avatar_url":"https://github.com/beenotung.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# backoff-pool\n\nA helper library to manage expotential backoff intervals of different resources.\n\nThis can be used to manage retry interval of login attempts per IP address and apply rate limit on abnormal request / rare API calls.\n\n[![npm Package Version](https://img.shields.io/npm/v/backoff-pool)](https://www.npmjs.com/package/backoff-pool)\n[![Minified Package Size](https://img.shields.io/bundlephobia/min/backoff-pool)](https://bundlephobia.com/package/backoff-pool)\n[![Minified and Gzipped Package Size](https://img.shields.io/bundlephobia/minzip/backoff-pool)](https://bundlephobia.com/package/backoff-pool)\n\n## Installation\n\n```bash\nnpm install backoff-pool\n```\n\n## Importing this package\n\nimport from typescript:\n\n```typescript\nimport { BackoffPool } from 'backoff-pool'\n```\n\nOr import from javascript:\n\n```javascript\nconst { BackoffPool } = require('backoff-pool')\n```\n\n## Typescript Types\n\n```typescript\nexport class BackoffPool\u003cKey = string | number\u003e {\n  constructor(options?: BackoffPoolOptions)\n\n  success(key: Key): void\n  fail(key: Key): void\n  applyRandomBackoff(key: Key, range?: number): void\n\n  getInterval(key: Key): number\n  getUnlockTime(key: Key): number | undefined\n\n  isLocked(key: Key): boolean\n  isAvailable(key: Key): boolean\n}\n\nexport interface BackoffPoolOptions {\n  defaultInterval?: number // default 0\n  initialBackoffInterval?: number // default 1 second\n  maxBackoffInterval?: number // default unlimited\n  backoffFactor?: number // default 2\n  randomBackoffRatio?: number // default 0.2 (20%)\n}\n\nexport let defaultBackoffPoolOptions: Required\u003cBackoffPoolOptions\u003e\n```\n\n## Usage Example\n\n\u003cdetails\u003e\n\u003csummary\u003eLogin attempt cooldown example\u003c/summary\u003e\n\n```typescript\nlet backoffPool = new BackoffPool({\n  defaultInterval: 0,\n  initialBackoffInterval: 2000,\n  backoffFactor: 2,\n})\n\nlet clientIP = 'stub'\n\nconsole.log('0', backoffPool.isAvailable(clientIP)) // true: is available\nconsole.log('0', backoffPool.isLocked(clientIP)) // false: not locked\nconsole.log('0', backoffPool.getUnlockTime(clientIP)) // undefined: not locked\n\nbackoffPool.fail(clientIP) // lock for 2 seconds\nconsole.log('1', backoffPool.isAvailable(clientIP)) // false: not available\nconsole.log('1', backoffPool.getUnlockTime(clientIP)) // Date.now() + 2000\n\nbackoffPool.fail(clientIP) // failed again, lock for 4 seconds\nbackoffPool.fail(clientIP) // failed again, lock for 8 seconds\nconsole.log('2', backoffPool.getInterval(clientIP)) // 8000: 8 seconds\n\nawait sleep(7 * 1000)\nconsole.log('7', backoffPool.isAvailable(clientIP)) // false: still locked\n\nawait sleep(1 * 1000)\nconsole.log('8', backoffPool.isAvailable(clientIP)) // true: unlocked now\n\nbackoffPool.success(clientIP) // reset the interval\nconsole.log('9', backoffPool.getInterval(clientIP)) // 0: same as defaultInterval\n\nbackoffPool.fail(clientIP) // lock for 2 seconds instead of 16 seconds\n\nawait sleep(2 * 1000)\nconsole.log('10', backoffPool.isLocked(clientIP)) // false: unlocked now\n```\n\n\u003c/details\u003e\n\nMore examples see [test/example.ts](./test/example.ts) and [test/core.test.ts](./test/core.test.ts)\n\n## License\n\nThis project is licensed with [BSD-2-Clause](./LICENSE)\n\nThis is free, libre, and open-source software. It comes down to four essential freedoms [[ref]](https://seirdy.one/2021/01/27/whatsapp-and-the-domestication-of-users.html#fnref:2):\n\n- The freedom to run the program as you wish, for any purpose\n- The freedom to study how the program works, and change it so it does your computing as you wish\n- The freedom to redistribute copies so you can help others\n- The freedom to distribute copies of your modified versions to others\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeenotung%2Fbackoff-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeenotung%2Fbackoff-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeenotung%2Fbackoff-pool/lists"}