{"_id":"@actualwave/resolve-or-timeout","_rev":"2-5eedfbe5bd3a1a37301b756a9bfa4a4e","name":"@actualwave/resolve-or-timeout","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@actualwave/resolve-or-timeout","version":"0.0.1","description":"Function that runs in Promise.race() your promise and a timeout, if timeout completes first resulting promise rejects with error.","main":"resolve-or-timeout.js","module":"index.js","types":"index.d.ts","keywords":["Promise","race","timeout"],"homepage":"https://gist.github.com/burdiuz/7b31f96827c4e5a070ec90be3f2e0572","bugs":{"url":"https://gist.github.com/burdiuz/7b31f96827c4e5a070ec90be3f2e0572","email":"burdiuz@gmail.com"},"license":"MIT","author":{"name":"Oleg Galaburda","email":"burdiuz@gmail.com","url":"http://actualwave.com/"},"gitHead":"a36efd0f122fab58f6b1b191b2e04334e34470df","_id":"@actualwave/resolve-or-timeout@0.0.1","_nodeVersion":"16.4.0","_npmVersion":"7.18.1","dist":{"integrity":"sha512-CuPL75JW8Oyc2AGCnFU6M36gUxkqAKXozYq9ONsg5OXswgZNOZOcXfaepuFiy9NOZVacm8HrFbeaazJmIpXS8Q==","shasum":"98c88a0294303298b8c0d2225382ee8734df671d","tarball":"https://registry.npmjs.org/@actualwave/resolve-or-timeout/-/resolve-or-timeout-0.0.1.tgz","fileCount":6,"unpackedSize":4257,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhxHmZCRA9TVsSAnZWagAAmR0P/3zDjRYkAoRaGMzWHkHi\n0EC5wQ8Uk5dJ/ay7ZAwKObLCTZM/KDvcKqGuY6AJMQE+uEr2IoVjsfrsw2Ip\na4X9rbo+omH9qxINfo4Siupp//h6QE7qNfh4I6kyG9JsKBguvs1QdWR8uQKj\nbrhiiycqmXcZV9G3P5VUlx/tbrmLMw0muwehutMMQESgvXHK0nPIOZewWSYB\noKr4mvLJ+J5GunzyhEG62juNYC9oddPd0PAmN+0pOUClfKGVeK/tpSF1dr7i\nqZC2CkfeUNfvNt2GZ5mjH9yXnod0+NrdQ/6UzusZVfnHuEAADs6YTIz5zq4x\nxMtR+X+ETatCIMIUQMsw4tlKrVyvWud+gSTC0UV0iDnTADCaTp3dFhFkn6kt\net9wIzSSGPF/hPng1REQ2fPzlMPa3guDkzDSlgqn7VHV7wcKafPfpIFMeASQ\nctSShR5hIRrbo9jc6CAb2MM5IZjxYA8pbzCUBnklNJSBlit+hGTXtNpoqYj5\nkf9unnQYKd5/Ax4DGuU0L+I+EcJ5oLXmtaTl2zESTLTXq9Qie2tFH6MLzBOu\n87rwno3VqtRWQk96ylF920wlhFw4hx4HPeBLWHasWS/Yp3c1/VrQGPz+DT+L\ntRg/rBWAfprYQQCWZ/7lIRDSzmsJTV76wDQPOBLUyVjsc9TKnZAr6yJiJlbp\nx+Z1\r\n=WXg5\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDa+OEQUrKju6dyMHncvfwJZJMhmGOdELvPwaq5r+i7CwIgcbS5mnT73YzpqpUEfSHS9JdCZtJ7+kB1ktXkUUCcFXw="}]},"_npmUser":{"name":"actualwave","email":"burdiuz@gmail.com"},"directories":{},"maintainers":[{"name":"actualwave","email":"burdiuz@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/resolve-or-timeout_0.0.1_1635691392902_0.9874893338018929"},"_hasShrinkwrap":false}},"time":{"created":"2021-10-31T14:43:12.860Z","0.0.1":"2021-10-31T14:43:13.009Z","modified":"2022-04-04T11:20:15.438Z"},"maintainers":[{"name":"actualwave","email":"burdiuz@gmail.com"}],"description":"Function that runs in Promise.race() your promise and a timeout, if timeout completes first resulting promise rejects with error.","homepage":"https://gist.github.com/burdiuz/7b31f96827c4e5a070ec90be3f2e0572","keywords":["Promise","race","timeout"],"author":{"name":"Oleg Galaburda","email":"burdiuz@gmail.com","url":"http://actualwave.com/"},"bugs":{"url":"https://gist.github.com/burdiuz/7b31f96827c4e5a070ec90be3f2e0572","email":"burdiuz@gmail.com"},"license":"MIT","readme":"# @actualwave/resolve-or-timeout\nFunction that runs in Promise.race() your promise and a timeout, if timeout completes first, resulting promise rejects with error.\n```typescript\nexport const resolveOrTimeout = <T = unknown>(\n  \n  // Promise or a function that will be passed to a Promise object\n  promiseOrHandler:\n    | Promise<T>\n    | ((\n        resolve: (data: T) => void,\n        reject?: (data: unknown) => void\n      ) => unknown),\n        \n  // timeout in milliseconds. if 0, race condition will not apply and original promise will be returned as is\n  timeout: number, \n    \n  // optional, timeout error message\n  timeoutError?: string, \n  \n  // optional callback that will be executed when timeout completes first\n  onTimeout?: (msg: string) => void \n) => Promise<T>;\n```\n\n### Example\n```javascript\ntry {\n  /*\n    if request resolves in less than 500 ms, you will get response\n  */\n  const response = await resolveOrTimeout(\n    fetch('/super/long/request'),\n    500,\n    'Sorry, your request takes toooooo long.',\n  );\n} catch (error) {\n  /*\n    if request takes longer than 500 ms, promise rejects with error message\n  */\n}\n```\nIt accepts promise or a function that will be passed to a promise.\n```javascript\nconst response = await resolveOrTimeout(\n  (resolve) => {\n    // do something then resolve\n  },\n  500\n);\n```","readmeFilename":"README.md"}