{"id":18063040,"url":"https://github.com/stagas/atomic","last_synced_at":"2025-04-11T15:13:33.339Z","repository":{"id":57186324,"uuid":"2549238","full_name":"stagas/atomic","owner":"stagas","description":"makes a function atomic with timeout and abort signal","archived":false,"fork":false,"pushed_at":"2022-01-20T06:36:42.000Z","size":11,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T11:21:47.451Z","etag":null,"topics":["abort","atomic","concurrency","promise","race-conditions","signal","timeout"],"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/stagas.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":"2011-10-10T16:13:02.000Z","updated_at":"2024-01-19T12:45:36.000Z","dependencies_parsed_at":"2022-09-14T14:21:33.170Z","dependency_job_id":null,"html_url":"https://github.com/stagas/atomic","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stagas%2Fatomic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stagas%2Fatomic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stagas%2Fatomic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stagas%2Fatomic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stagas","download_url":"https://codeload.github.com/stagas/atomic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248429117,"owners_count":21101785,"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":["abort","atomic","concurrency","promise","race-conditions","signal","timeout"],"created_at":"2024-10-31T05:09:13.758Z","updated_at":"2025-04-11T15:13:33.322Z","avatar_url":"https://github.com/stagas.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eatomic\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\nmakes a function atomic with timeout and abort signal\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n   \u003ca href=\"#install\"\u003e        🔧 \u003cstrong\u003eInstall\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"#example\"\u003e        🧩 \u003cstrong\u003eExample\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"#api\"\u003e            📜 \u003cstrong\u003eAPI docs\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"https://github.com/stagas/atomic/releases\"\u003e 🔥 \u003cstrong\u003eReleases\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"#contribute\"\u003e     💪🏼 \u003cstrong\u003eContribute\u003c/strong\u003e\u003c/a\u003e\n · \u003ca href=\"https://github.com/stagas/atomic/issues\"\u003e   🖐️ \u003cstrong\u003eHelp\u003c/strong\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n***\n\n## Install\n\n```sh\n$ npm i atomic\n```\n\n## API\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n#### Table of Contents\n\n*   [atomic](#atomic)\n    *   [Parameters](#parameters)\n\n### atomic\n\n[src/index.ts:33-78](https://github.com/stagas/atomic/blob/2a0a9f5694e915eb4fe86dea4895ed398d1458c3/src/index.ts#L33-L78 \"Source code on GitHub\")\n\nMakes a function atomic.\n\n```js\nconst fn = atomic(signal =\u003e async () =\u003e {\n  // some long async operation\n\n  // if we've been aborted during the long\n  // async process above, we wouldn't want\n  // to continue so lets return here\n  if (signal.aborted) return\n\n  // do things here if we didn't abort\n}, 500) // timeout at 500ms (don't pass anything for no timeout)\nfn()\nfn()\nfn()\nawait fn() // this will run after the above have settled\n```\n\n#### Parameters\n\n*   `signalClosure` **function (signal: AbortSignal): function (...args: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\\\u003cany\u003e): [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\\u003cany\u003e** A function that receives the signal object\n    from an AbortController and returns the function to become atomic.\n*   `maxTimeMs` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Time in milliseconds to timeout the operation. Will also signal abort.\n\nReturns **any** An atomic function\n\n## Contribute\n\n[Fork](https://github.com/stagas/atomic/fork) or\n[edit](https://github.dev/stagas/atomic) and submit a PR.\n\nAll contributions are welcome!\n\n## License\n\nMIT © 2022\n[stagas](https://github.com/stagas)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstagas%2Fatomic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstagas%2Fatomic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstagas%2Fatomic/lists"}