{"id":18013222,"url":"https://github.com/tajpouria/circuit-breaker","last_synced_at":"2025-08-31T01:32:34.641Z","repository":{"id":39664027,"uuid":"497237560","full_name":"tajpouria/circuit-breaker","owner":"tajpouria","description":"A zero-dependency, fail-fast circuit breaker for promises.","archived":false,"fork":false,"pushed_at":"2022-05-30T16:26:07.000Z","size":63,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-30T03:54:52.921Z","etag":null,"topics":["circuit-breaker","fail-fast","fuse","rolling-windows"],"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/tajpouria.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-05-28T06:46:46.000Z","updated_at":"2022-05-30T18:43:10.000Z","dependencies_parsed_at":"2022-09-20T07:11:40.151Z","dependency_job_id":null,"html_url":"https://github.com/tajpouria/circuit-breaker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tajpouria/circuit-breaker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tajpouria%2Fcircuit-breaker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tajpouria%2Fcircuit-breaker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tajpouria%2Fcircuit-breaker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tajpouria%2Fcircuit-breaker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tajpouria","download_url":"https://codeload.github.com/tajpouria/circuit-breaker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tajpouria%2Fcircuit-breaker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272929996,"owners_count":25017057,"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-08-30T02:00:09.474Z","response_time":77,"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":["circuit-breaker","fail-fast","fuse","rolling-windows"],"created_at":"2024-10-30T03:20:28.894Z","updated_at":"2025-08-31T01:32:34.610Z","avatar_url":"https://github.com/tajpouria.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Circuit Breaker [![CI](https://github.com/tajpouria/circuit-breaker/actions/workflows/ci.yaml/badge.svg)](https://github.com/tajpouria/circuit-breaker/actions/workflows/ci.yaml)\n\nA zero-dependency Node.js circuit breaker that executes asynchronous functions and monitors their execution status. When things start failing, circuit breaker plays dead and fails fast.\n\n## Usage\n\n```ts\nimport CircuitBreaker from \"circuit-breaker\";\n\n(async () =\u003e {\n  const breaker = new CircuitBreaker(AsyncAction, {\n    timeout: 100,\n    maxFailures: 3,\n    resetTimeout: 3000,\n    debug: true,\n  });\n\n  // Initially, breaker must be in the CLOSE state\n  await breaker.fire(...args);\n\n  // Reject the promise $maxFailures times to OPEN the breaker\n  for (let i = 1; i \u003c= breaker.options.maxFailures; i++)\n    await breaker.fire(...args).catch(() =\u003e {});\n\n  // Breaker must be in the OPEN state for the next $resetTimeout milliseconds\n  breaker.fire(...args).catch(() =\u003e {});\n\n  // Wait for $resetTimeout milliseconds\n  await sleep(breaker.options.resetTimeout);\n\n  // Resolve the promise 1 time to CLOSE the breaker\n  await breaker.fire(...args);\n\n  // Breaker must be in the CLOSE state\n  for (let i = 1; i \u003c= breaker.options.maxFailures - 1; i++)\n    breaker.fire(...args).catch(() =\u003e {});\n\n  // Resolve the promise 1 time to CLOSE the breaker\n  await breaker\n    .fire(...args, (breaker.options.timeout as number) + 1)\n    .catch(() =\u003e {});\n})();\n```\n\nReadme sample can be found in the [example](./example).\n\n## Configuration Options\n\n| Property       | Type                  | Explanation                                                                                                                                  | Default Value        |\n| -------------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- |\n| `timeout`      | `Number` \\| `Boolean` | The time in **milliseconds** that action should be allowed to execute before timing out. Timeout can be disabled by setting this to `false`. | `10000` (10 seconds) |\n| `maxFailures`  | `Number`              | The number of times the circuit can fail before opening.                                                                                     | `10`                 |\n| `resetTimeout` | `Number`              | The time in **milliseconds** to wait before setting the breaker to `halfOpen` state, and trying the action again.                            | `10000` (10 seconds) |\n| `debug`        | `Boolean`             | Enable/disable debug logging.                                                                                                                | `false`              |\n\n## How is it tracks the circuit breaker status?\n\nThe [Status](./src/status.ts) class, Tracks execution status for a given circuit breaker.\nIt listen for all events on the circuit breaker and track them in a rolling statistical window.\nThe window consists of an array of Objects like this:\n\n```ts\n[\n  { failures: 0, successes: 0, rejects: 0, fires: 0, timeouts: 0 },\n  { failures: 0, successes: 0, rejects: 0, fires: 0, timeouts: 0 },\n  { failures: 0, successes: 0, rejects: 0, fires: 0, timeouts: 0 },\n];\n```\n\nEach representing the counts for a circuit breaker events.\n\n## Local Development\n\nClone the repository, and navigate into it.\n\nInstall development dependencies:\n\n```sh\nyarn\n```\n\nMake your changes, then run tests:\n\n```sh\nyarn test\n```\n\n## License\n\n[MIT License](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftajpouria%2Fcircuit-breaker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftajpouria%2Fcircuit-breaker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftajpouria%2Fcircuit-breaker/lists"}