{"id":24455558,"url":"https://github.com/nixjs/backoff-typescript","last_synced_at":"2026-05-20T02:52:11.152Z","repository":{"id":62239821,"uuid":"558689206","full_name":"nixjs/backoff-typescript","owner":"nixjs","description":"A small library which handles decaying constant/linear/exponential backOff","archived":false,"fork":false,"pushed_at":"2022-10-28T04:40:40.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-05T17:51:09.424Z","etag":null,"topics":["attempt","backoff","javascript","polling","retry","retry-strategies","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nixjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-28T04:19:26.000Z","updated_at":"2022-10-28T05:48:53.000Z","dependencies_parsed_at":"2022-10-29T01:32:25.274Z","dependency_job_id":null,"html_url":"https://github.com/nixjs/backoff-typescript","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/nixjs%2Fbackoff-typescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixjs%2Fbackoff-typescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixjs%2Fbackoff-typescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixjs%2Fbackoff-typescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nixjs","download_url":"https://codeload.github.com/nixjs/backoff-typescript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243544668,"owners_count":20308168,"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":["attempt","backoff","javascript","polling","retry","retry-strategies","typescript"],"created_at":"2025-01-21T02:13:44.088Z","updated_at":"2026-05-20T02:52:11.113Z","avatar_url":"https://github.com/nixjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @nixjs23n6/backoff-typescript\n\nA small library which handles decaying constant/linear/exponential backOff\n\n## Quick Setup\n\n### ConstantBackoff\n\nThe ConstantBackoff will make the websocket wait a constant time between each connection retry. To use the Constant Backoff with a wait-time of 1 second:\n\n```typescript\nconst backoff  = new ConstantBackoff(1000)\nsetTimeout(() =\u003e {\n    // todo something\n}, backoff)\n```\n\n### LinearBackoff\n\nThe LinearBackoff linearly increases the wait-time between connection-retries until an optional maximum is reached. To use the LinearBackoff to initially wait 0 seconds and increase the wait-time by 2 second with every retry until a maximum of 12 seconds is reached:\n\n```typescript\nconst backoff  = new LinearBackoff(0, 2000, 12000)\nsetTimeout(() =\u003e {\n    // todo something\n}, backoff)\n```\n\n### ExponentialBackoff\n\nThe ExponentialBackoff doubles the backoff with every retry until a maximum is reached. This is modelled after the binary exponential-backoff algorithm used in computer-networking. To use the ExponentialBackoff that will produce the series [100, 200, 400, 800, 1600, 3200, 6400]:\n\n```typescript\nconst backoff  = new ExponentialBackoff(100, 7)\nsetTimeout(() =\u003e {\n    // todo something\n}, backoff)\n```\n\n## Examples\n\n### Redux-saga\n\n```typescript\nimport { LinearBackOff, BaseBackOff } from '@nixjs23n6/backoff-typescript'\n\nfunction* pollPriceSaga(backOff: BaseBackOff) {\n    while (true) {\n        try {\n            const time = backOff.next()\n            if (time === 15000) {\n                backOff.reset()\n            }\n\n            const result = yield call(FETCH_PRICE)\n            yield put(onFetchPriceSuccess(result))\n            if (time \u003e 0) yield delay(time)\n            yield delay(time)\n        } catch (err) {\n            yield put(onFetchPriceFailure(err))\n        }\n    }\n}\n\nfunction* watchPriceSaga() {\n    while (true) {\n        yield take(coingeckoSlice.onStartFetchPrice)\n\n        const backOff = new LinearBackOff(0, 10000, 15000)\n        yield race({\n            task: call(pollPriceSaga, backOff),\n            cancel: take(coingeckoSlice.onStopFetchPrice)\n        })\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixjs%2Fbackoff-typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnixjs%2Fbackoff-typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixjs%2Fbackoff-typescript/lists"}