{"id":28795597,"url":"https://github.com/bakerface/abortify","last_synced_at":"2025-08-04T18:07:25.223Z","repository":{"id":42844682,"uuid":"262869261","full_name":"bakerface/abortify","owner":"bakerface","description":"A cancellation token implementation in typescript","archived":false,"fork":false,"pushed_at":"2023-01-07T04:41:33.000Z","size":835,"stargazers_count":2,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-18T03:09:29.747Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/bakerface.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":"2020-05-10T20:25:12.000Z","updated_at":"2023-11-20T00:11:43.000Z","dependencies_parsed_at":"2023-02-06T12:01:26.223Z","dependency_job_id":null,"html_url":"https://github.com/bakerface/abortify","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/bakerface/abortify","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakerface%2Fabortify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakerface%2Fabortify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakerface%2Fabortify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakerface%2Fabortify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bakerface","download_url":"https://codeload.github.com/bakerface/abortify/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bakerface%2Fabortify/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265980971,"owners_count":23859555,"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":[],"created_at":"2025-06-18T03:09:30.177Z","updated_at":"2025-07-20T16:03:33.436Z","avatar_url":"https://github.com/bakerface.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# abortify\n**Create abortable async functions with ease**\n\n## Abortable\n\nAn **abortable** is an asynchronous function that can be aborted. An abortable\nis passed a `resolve` and `reject` callback, just like the `Promise`\nconstructor, and returns a function for aborting the operation. Consider the\nfollowing definition of an abortable version of `setTimeout`:\n\n``` typescript\nimport type { Abortable } from \"abortify\";\n\nexport function setAbortableTimeout(ms: number): Abortable\u003cvoid\u003e {\n  return (resolve, reject) =\u003e {\n    const handle = setTimeout(resolve, ms);\n    return () =\u003e clearTimeout(handle);\n  };\n}\n```\n\n## abortify\n\nThe `abortify` function converts abortable functions into functions that return\na `Promise`. It works just like `util.promisify`, with a few additions:\n\n- The function will accept an `AbortSignal` as an optional final argument.\n- The function will throw an `AbortError` when the signal is aborted.\n- The abortable will be aborted before the promise resolves or rejects.\n\nConsider the following definition of an abortified version of the\n`setAbortableTimeout` above:\n\n``` typescript\nimport { abortify } from \"abortify\";\n\nexport const sleep = abortify(setAbortableTimeout);\n\n// The sleep function above has the following signature:\n// (ms: number, signal?: AbortSignal) =\u003e Promise\u003cvoid\u003e\n```\n\n## Using abortified functions\n\nOnce you have abortified a function you use it just like any other async\nfunction. Consider the following example:\n\n``` typescript\nimport { sleep } from \"abortify\";\n\n// this function will print a message every second\n// this function will only exit when the signal is aborted\nasync function forever(signal?: AbortSignal) {\n  for (;;) {\n    await sleep(1000, signal);\n    console.log(\"another second has passed\");\n  }\n}\n\nasync function main() {\n  const controller = new AbortController();\n\n  // abort after a short amount of time\n  setTimeout(() =\u003e controller.abort(), 5000);\n\n  try {\n    await forever(controller.signal);\n  } catch (err) {\n    if (err.aborted) {\n      console.error(err); // AbortError: The operation was aborted\n    }\n  }\n}\n\nmain();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbakerface%2Fabortify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbakerface%2Fabortify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbakerface%2Fabortify/lists"}