{"_id":"@open-draft/until","_rev":"4239003","name":"@open-draft/until","description":"Gracefully handle a Promise using async/await.","dist-tags":{"latest":"3.0.1"},"maintainers":[{"name":"kettanaito","email":""}],"time":{"modified":"2026-03-23T00:55:05.000Z","created":"2020-03-24T16:11:28.033Z","3.0.1":"2025-09-20T10:35:33.486Z","3.0.0":"2025-09-20T10:26:53.319Z","2.1.0":"2023-04-18T16:50:45.090Z","2.0.0":"2022-02-16T16:10:08.127Z","1.0.3":"2020-05-31T08:25:06.736Z","1.0.2":"2020-03-24T16:51:20.223Z","1.0.1":"2020-03-24T16:16:53.835Z","1.0.0":"2020-03-24T16:11:28.033Z"},"users":{},"author":{"name":"Artem Zakharchenko","url":"https://github.com/kettanaito"},"repository":{"type":"git","url":"git+https://github.com/open-draft/until.git"},"versions":{"3.0.1":{"type":"module","name":"@open-draft/until","version":"3.0.1","description":"Gracefully handle a Promise using async/await.","main":"./lib/index.js","types":"./lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","default":"./lib/index.js"}},"homepage":"https://github.com/open-draft/until","repository":{"type":"git","url":"git+https://github.com/open-draft/until.git"},"author":{"name":"Artem Zakharchenko","url":"https://github.com/kettanaito"},"license":"MIT","funding":"https://github.com/sponsors/kettanaito","keywords":["async","promise","handle","gracefully","tuple","util"],"devDependencies":{"@ossjs/release":"^0.8.1","@rolldown/binding-darwin-arm64":"1.0.0-beta.38","publint":"^0.3.13","tsdown":"^0.15.3","typescript":"^5.9.2","vitest":"^3.2.4"},"scripts":{"dev":"tsdown -w","test":"vitest","lint":"publint","build":"tsdown","release":"release publish"},"_id":"@open-draft/until@3.0.1","bugs":{"url":"https://github.com/open-draft/until/issues"},"_integrity":"sha512-s7/9ELP4aP9YZtW7RJaa0Xf3RISaRH9+EFN18FtykJYRHGNrl8f9ymvoNXzjhrjmftFvkQudtuDU9RYhk0xs3A==","_resolved":"/tmp/d68f5c2a9fb473113ba7542343564bb0/open-draft-until-3.0.1.tgz","_from":"file:open-draft-until-3.0.1.tgz","_nodeVersion":"22.19.0","_npmVersion":"10.9.3","dist":{"shasum":"6d35fa5842e3f7288289cf48de0a83f3b83cc5ac","size":3796,"noattachment":false,"key":"/@open-draft/until/-/@open-draft/until-3.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@open-draft/until/download/@open-draft/until-3.0.1.tgz"},"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"directories":{},"maintainers":[{"name":"kettanaito","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/until_3.0.1_1758364533288_0.33642240251246913"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-09-20T10:35:33.486Z","publish_time":1758364533486,"_source_registry_name":"default","_cnpm_publish_time":1758364533486},"3.0.0":{"type":"module","name":"@open-draft/until","version":"3.0.0","description":"Gracefully handle a Promise using async/await.","main":"./lib/index.js","types":"./lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","default":"./lib/index.js"}},"homepage":"https://github.com/open-draft/until","repository":{"type":"git","url":"git+https://github.com/open-draft/until.git"},"author":{"name":"Artem Zakharchenko","url":"https://github.com/kettanaito"},"license":"MIT","funding":"https://github.com/sponsors/kettanaito","keywords":["async","promise","handle","gracefully","tuple","util"],"devDependencies":{"@ossjs/release":"^0.8.1","@rolldown/binding-darwin-arm64":"1.0.0-beta.38","publint":"^0.3.13","tsdown":"^0.15.3","typescript":"^5.9.2","vitest":"^3.2.4"},"scripts":{"dev":"tsdown -w","test":"vitest","lint":"publint","build":"tsdown","release":"release publish"},"_id":"@open-draft/until@3.0.0","bugs":{"url":"https://github.com/open-draft/until/issues"},"_integrity":"sha512-NMF/eJFYzCqUoC+AmGR2CzbRHhn6CzeCej6TV6AGvJPlTwjbn+NyreJzgQs5rh4qJxnkSWLpg6Vdpe4ZNEeu9Q==","_resolved":"/tmp/22220599cb9f2cdf49ba13331e202f60/open-draft-until-3.0.0.tgz","_from":"file:open-draft-until-3.0.0.tgz","_nodeVersion":"22.19.0","_npmVersion":"10.9.3","dist":{"shasum":"9ed42f524c2f7b5631332cedf03c4e7ff7f403a6","size":3681,"noattachment":false,"key":"/@open-draft/until/-/@open-draft/until-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@open-draft/until/download/@open-draft/until-3.0.0.tgz"},"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"directories":{},"maintainers":[{"name":"kettanaito","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/until_3.0.0_1758364013147_0.013188082460631634"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-09-20T10:26:53.319Z","publish_time":1758364013319,"_source_registry_name":"default","_cnpm_publish_time":1758364013319},"2.1.0":{"name":"@open-draft/until","version":"2.1.0","description":"Gracefully handle a Promise using async/await.","main":"./lib/index.js","module":"./lib/index.mjs","types":"./lib/index.d.ts","exports":{".":{"types":"./lib/index.d.ts","require":"./lib/index.js","import":"./lib/index.mjs","default":"./lib/index.mjs"}},"repository":{"type":"git","url":"git+https://github.com/open-draft/until.git"},"author":{"name":"Artem Zakharchenko","email":"kettanaito@gmail.com"},"license":"MIT","devDependencies":{"@ossjs/release":"^0.5.1","@types/jest":"^26.0.22","jest":"^26.6.3","ts-jest":"^26.5.4","tsup":"^6.2.3","typescript":"^4.2.4"},"scripts":{"start":"tsc -w","test":"jest","build":"tsup","release":"release publish"},"bugs":{"url":"https://github.com/open-draft/until/issues"},"homepage":"https://github.com/open-draft/until#readme","_id":"@open-draft/until@2.1.0","_integrity":"sha512-U69T3ItWHvLwGg5eJ0n3I62nWuE6ilHlmz7zM0npLBRvPRd7e6NYmg54vvRtP5mZG7kZqZCFVdsTWo7BPtBujg==","_resolved":"/tmp/39f5efd50d771760971c1aa799bfb36f/open-draft-until-2.1.0.tgz","_from":"file:open-draft-until-2.1.0.tgz","_nodeVersion":"18.15.0","_npmVersion":"9.5.0","dist":{"shasum":"0acf32f470af2ceaf47f095cdecd40d68666efda","size":4032,"noattachment":false,"key":"/@open-draft/until/-/@open-draft/until-2.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@open-draft/until/download/@open-draft/until-2.1.0.tgz"},"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"directories":{},"maintainers":[{"name":"kettanaito","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/until_2.1.0_1681836644918_0.06186753941365919"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-04-18T16:50:45.090Z","publish_time":1681836645090,"_cnpm_publish_time":1681836645090},"2.0.0":{"name":"@open-draft/until","version":"2.0.0","description":"Gracefully handle a Promise using async/await.","main":"lib/index.js","repository":{"type":"git","url":"https://github.com/open-draft/until.git"},"author":{"name":"Artem Zakharchenko","email":"kettanaito@gmail.com"},"license":"MIT","devDependencies":{"@types/jest":"^26.0.22","jest":"^26.6.3","ts-jest":"^26.5.4","typescript":"^4.2.4"},"scripts":{"start":"tsc -w","test":"jest","build":"tsc --build tsconfig.json","prepublishOnly":"yarn test && yarn build"},"licenseText":"MIT License\n\nCopyright (c) 2021 Artem Zakharchenko\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@open-draft/until@2.0.0","dist":{"shasum":"13d79bb827eb1be21cea4d29cdc60ca3312ec02f","size":2718,"noattachment":false,"key":"/@open-draft/until/-/@open-draft/until-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@open-draft/until/download/@open-draft/until-2.0.0.tgz"},"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"directories":{},"maintainers":[{"name":"kettanaito","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/until_2.0.0_1645027807856_0.2607082055854695"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-02-16T16:10:15.224Z","publish_time":1645027808127,"_cnpm_publish_time":1645027808127},"1.0.3":{"name":"@open-draft/until","version":"1.0.3","description":"Gracefully handle a Promise using async/await.","main":"lib/index.js","repository":{"type":"git","url":"https://github.com/open-draft/until.git"},"author":{"name":"Artem Zakharchenko","email":"kettanaito@gmail.com"},"license":"MIT","devDependencies":{"@types/jest":"^25.1.4","jest":"^25.1.0","ts-jest":"^25.2.1","typescript":"^3.8.3"},"scripts":{"test":"jest","build":"tsc --build tsconfig.json","prepublishOnly":"yarn test && yarn build"},"_id":"@open-draft/until@1.0.3","dist":{"shasum":"db9cc719191a62e7d9200f6e7bab21c5b848adca","size":1869,"noattachment":false,"key":"/@open-draft/until/-/@open-draft/until-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/@open-draft/until/download/@open-draft/until-1.0.3.tgz"},"maintainers":[{"name":"kettanaito","email":""}],"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/until_1.0.3_1590913506605_0.92808929223403"},"_hasShrinkwrap":false,"publish_time":1590913506736,"_cnpm_publish_time":1590913506736,"_cnpmcore_publish_time":"2021-12-16T18:59:28.330Z"},"1.0.2":{"name":"@open-draft/until","version":"1.0.2","description":"Gracefully handle a Promise using async/await.","main":"lib/index.js","repository":{"type":"git","url":"git@github.com:open-draft/until.git"},"author":{"name":"Artem Zakharchenko","email":"kettanaito@gmail.com"},"license":"MIT","devDependencies":{"@types/jest":"^25.1.4","jest":"^25.1.0","ts-jest":"^25.2.1","typescript":"^3.8.3"},"scripts":{"test":"jest","build":"tsc --build tsconfig.json","prepublishOnly":"yarn test && yarn build"},"_id":"@open-draft/until@1.0.2","dist":{"shasum":"9ca97314d58ac13e343dd0516d3f1fb0a656998d","size":1276,"noattachment":false,"key":"/@open-draft/until/-/@open-draft/until-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/@open-draft/until/download/@open-draft/until-1.0.2.tgz"},"maintainers":[{"name":"kettanaito","email":""}],"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/until_1.0.2_1585068680094_0.2851445876833827"},"_hasShrinkwrap":false,"publish_time":1585068680223,"_cnpm_publish_time":1585068680223,"_cnpmcore_publish_time":"2021-12-16T18:59:28.528Z"},"1.0.1":{"name":"@open-draft/until","version":"1.0.1","description":"Gracefully handle a Promise using async/await.","main":"lib/index.js","repository":{"type":"git","url":"git@github.com:open-draft/until.git"},"author":{"name":"Artem Zakharchenko","email":"kettanaito@gmail.com"},"license":"MIT","devDependencies":{"@types/jest":"^25.1.4","jest":"^25.1.0","ts-jest":"^25.2.1","typescript":"^3.8.3"},"scripts":{"test":"jest","build":"tsc --build tsconfig.json","prepublishOnly":"yarn test && yarn build"},"_id":"@open-draft/until@1.0.1","dist":{"shasum":"f7e22c87245c1a25a279a9d323e2ae93ec59c159","size":1261,"noattachment":false,"key":"/@open-draft/until/-/@open-draft/until-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/@open-draft/until/download/@open-draft/until-1.0.1.tgz"},"maintainers":[{"name":"kettanaito","email":""}],"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/until_1.0.1_1585066613739_0.5157534729966682"},"_hasShrinkwrap":false,"publish_time":1585066613835,"_cnpm_publish_time":1585066613835,"_cnpmcore_publish_time":"2021-12-16T18:59:28.914Z"},"1.0.0":{"name":"@open-draft/until","version":"1.0.0","description":"Gracefully handle a Promise using async/await.","main":"lib/index.js","repository":{"type":"git","url":"git@github.com:open-draft/until.git"},"author":{"name":"Artem Zakharchenko","email":"kettanaito@gmail.com"},"license":"MIT","devDependencies":{"@types/jest":"^25.1.4","jest":"^25.1.0","ts-jest":"^25.2.1","typescript":"^3.8.3"},"scripts":{"test":"jest","build":"tsc --build tsconfig.json","prepublishOnly":"yarn test && yarn build"},"_id":"@open-draft/until@1.0.0","dist":{"shasum":"4f0a89c4fb5e2868bfa02927a97e5b48f53d1a17","size":1250,"noattachment":false,"key":"/@open-draft/until/-/@open-draft/until-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@open-draft/until/download/@open-draft/until-1.0.0.tgz"},"maintainers":[{"name":"kettanaito","email":""}],"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/until_1.0.0_1585066287488_0.887769747590575"},"_hasShrinkwrap":false,"publish_time":1585066288033,"_cnpm_publish_time":1585066288033,"_cnpmcore_publish_time":"2021-12-16T18:59:29.123Z"}},"readme":"> ⚠️ **This package has been re-published as [`until-async`](https://www.npmjs.com/package/until-async)**. Please update to that package instead as it will receive updates and fixes from now on. Thank you.\n\n# `until`\n\nGracefully handle a Promise using `async`/`await`.\n\n## Why?\n\nWith the addition of `async`/`await` keywords in ECMAScript 2017 the handling of Promises became much easier. However, one must keep in mind that the `await` keyword provides no standard error handling API. Consider this usage:\n\n```js\nasync function getUser(id) {\n  const data = await fetchUser(id)\n  // Work with \"data\"...\n}\n```\n\nIn case `fetchUser()` throws an error, the entire `getUser()` function's scope will terminate. Because of this, it's recommended to implement error handling using `try`/`catch` block wrapping `await` expressions:\n\n```js\nasync function getUser(id) {\n  let data = null\n\n  try {\n    data = await asyncAction()\n  } catch (error) {\n    console.error(error)\n  }\n\n  // Work with \"data\"...\n}\n```\n\nWhile this is a semantically valid approach, constructing `try`/`catch` around each awaited operation may be tedious and get overlooked at times. Such error handling also introduces separate closures for execution and error scenarios of an asynchronous operation.\n\nThis library encapsulates the `try`/`catch` error handling in a utility function that does not create a separate closure and exposes a NodeJS-friendly API to work with errors and resolved data.\n\n## Getting started\n\n### Install\n\n```bash\nnpm install @open-draft/until\n```\n\n### Usage\n\n```js\nimport { until } from '@open-draft/until'\n\nasync function getUserById(id) {\n  const [error, data] = await until(() => fetchUser(id))\n\n  if (error) {\n    return handleError(error)\n  }\n\n  return data\n}\n```\n\n### Usage with TypeScript\n\n```ts\nimport { until } from '@open-draft/until'\n\ninterface User {\n  firstName: string\n  age: number\n}\n\ninterface UserFetchError {\n  type: 'FORBIDDEN' | 'NOT_FOUND'\n  message?: string\n}\n\nasync function getUserById(id: string) {\n  const [error, data] = await until<UserFetchError, User>(() => fetchUser(id))\n\n  if (error) {\n    return handleError(error.type, error.message)\n  }\n\n  return data.firstName\n}\n```\n\n## Frequently asked questions\n\n### Why does `until` accept a function and not a `Promise` directly?\n\nThis has been intentionally introduced to await a single logical unit as opposed to a single `Promise`.\n\n```js\n// Notice how a single \"until\" invocation can handle\n// a rather complex piece of logic. This way any rejections\n// or exceptions happening within the given function\n// can be handled via the same \"error\".\nconst [error, data] = until(async () => {\n  const user = await fetchUser()\n  const nextUser = normalizeUser(user)\n  const transaction = await saveModel('user', user)\n\n  invariant(transaction.status === 'OK', 'Saving user failed')\n\n  return transaction.result\n})\n\nif (error) {\n  // Handle any exceptions happened within the function.\n}\n```\n\n## Special thanks\n\n- [giuseppegurgone](https://twitter.com/giuseppegurgone) for the discussion about the original `until` API.\n","_attachments":{},"homepage":"https://github.com/open-draft/until","bugs":{"url":"https://github.com/open-draft/until/issues"},"license":"MIT"}