{"id":22355720,"url":"https://github.com/zbo14/oathbreaker","last_synced_at":"2025-10-18T07:41:31.941Z","repository":{"id":94588779,"uuid":"445674876","full_name":"zbo14/oathbreaker","owner":"zbo14","description":"Cancel pending promises with ease!","archived":false,"fork":false,"pushed_at":"2022-01-10T17:22:02.000Z","size":97,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T13:13:05.737Z","etag":null,"topics":["abortcontroller","abortsignal","async","promise","promises"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/oathbreaker","language":"JavaScript","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/zbo14.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-01-07T23:05:52.000Z","updated_at":"2022-01-10T17:22:06.000Z","dependencies_parsed_at":"2023-04-29T21:46:56.319Z","dependency_job_id":null,"html_url":"https://github.com/zbo14/oathbreaker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zbo14/oathbreaker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Foathbreaker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Foathbreaker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Foathbreaker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Foathbreaker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zbo14","download_url":"https://codeload.github.com/zbo14/oathbreaker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Foathbreaker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001949,"owners_count":26083226,"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-09T02:00:07.460Z","response_time":59,"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":["abortcontroller","abortsignal","async","promise","promises"],"created_at":"2024-12-04T14:07:47.697Z","updated_at":"2025-10-09T18:06:55.971Z","avatar_url":"https://github.com/zbo14.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oathbreaker\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\n\nCancel pending promises with ease!\n\n## Install\n\n`npm i oathbreaker`\n\n## Usage\n\n### `Oath()`\n\nCreate an `Oath` and break it:\n\n```js\nconst Oath = require('oathbreaker')\n\nconst oath = Oath((resolve, reject) =\u003e {\n  const t = setTimeout(() =\u003e resolve('ok'), 5e3)\n\n  return () =\u003e clearTimeout(t)\n})\n\nsetTimeout(() =\u003e oath.break(), 3e3)\n```\n\nThe executor function return value should be falsy or a function. If a function's returned, it's called if/when the oath is broken.\n\nThe executor function takes an optional 3rd argument. This is an [`AbortSignal`](https://nodejs.org/docs/latest-v16.x/api/globals.html#class-abortsignal), which can be passed to other methods (e.g. `https.request()`) or checked in business logic to see whether the oath was broken:\n\n```js\nconst https = require('https')\nconst Oath = require('oathbreaker')\n\nconst oath1 = Oath((resolve, reject, signal) =\u003e {\n  https.get('\u003curl\u003e', { signal }, res =\u003e {\n    // handle response\n  }).once('error', reject)\n})\n\nconst oath2 = Oath((resolve, reject, signal) =\u003e {\n  // do some stuff\n\n  if (signal.aborted) return\n\n  // do some other stuff\n})\n```\n\n### `Oath.all()`\n\nSimilar to `Promise.all()` except it breaks other oaths (i.e. cancels pending promises) when 1 rejects:\n\n```js\nOath.all([oath1, oath2, ... ])\n  .then(() =\u003e {\n    // all promises resolved\n  })\n  .catch(() =\u003e {\n    // 1 promise rejected,\n    // others pending are canceled\n  })\n```\n\n### `Oath.any()`\n\nSimilar to `Promise.any()` except it breaks other oaths when 1 resolves:\n\n```js\nOath.any([oath1, oath2, ... ])\n  .then(() =\u003e {\n    // 1 promise resolved,\n    // others pending are canceled\n  })\n  .catch(() =\u003e {\n    // All promises rejected\n  })\n```\n\n### `Oath.race()`\n\nSimilar to `Promise.race()` except it breaks other oaths when 1 resolves *or* rejects:\n\n```js\nOath.race([oath1, oath2, ... ])\n  .then(() =\u003e {\n    // 1 promise resolved,\n    // others pending are canceled\n  })\n  .catch(() =\u003e {\n    // 1 promise rejected,\n    // others pending are canceled\n  })\n```\n\n## Test\n\n`npm test`\n\n## Lint\n\n`npm run lint` or `npm run lint:fix`\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbo14%2Foathbreaker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzbo14%2Foathbreaker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbo14%2Foathbreaker/lists"}