{"name":"p-timeout","version":"3.0.0","description":"Timeout a promise after a specified amount of time","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-timeout.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd-check"},"keywords":["promise","timeout","error","invalidate","async","await","promises","time","out","cancel","bluebird"],"dependencies":{"p-finally":"^1.0.0"},"devDependencies":{"ava":"^1.3.1","delay":"^4.1.0","p-cancelable":"^1.1.0","tsd-check":"^0.3.0","xo":"^0.24.0"},"gitHead":"c79394a096b1707c21597cdef09e5695883bc42c","bugs":{"url":"https://github.com/sindresorhus/p-timeout/issues"},"homepage":"https://github.com/sindresorhus/p-timeout#readme","_id":"p-timeout@3.0.0","_nodeVersion":"8.15.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-HKUsVzU+2A+CcItUxgZ4Q1th5Hh2DHtSsh7gLTMkrL8Ki4Ss736nFp+yqb9M/ZKSKb5il0IXeLzBmUqD3k3mzQ==","shasum":"1bbd42db28c669efd02e1a82ccf14dc59eb57ed1","tarball":"http://registry-npm.ywwl.com/p-timeout/download/p-timeout-3.0.0.tgz","fileCount":5,"unpackedSize":6792,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJch2zHCRA9TVsSAnZWagAAb7gP/jFKJLXKqw0M46MzBpIw\nj6FhWAKis8k4B+QTZhVldh71LYYA8zmAsNRpXXlhDrXoBZw3JU8kUJNYHPpm\nwCr8F1KC5b+lzRBtFfq0Fmt47QPBfHLlOCXwLYRuGBbrRbWa7qPIHODCLF03\nQw3DIiUn59FPOyaaVys20yC4roN2VyOzwGQGU3gh3xULJeYZiJ2xT5r4rRuX\njiQG3xbGmSuB0pb0SNW46nYfv3BecSyLQrHcGaSGP8dOppUtkVMgsg3CND2S\ncTQ1B43aSNPwqrduvO1cVzssOjukn5LucX8+5sIYyWckDQQ9qWDDsbM/Ajey\nxZPpTYqxpR7N1tXrLJqNrlWpfWVgWq37YBY4e+NU6bHRF3ZDdA5mCBQ/g+xj\n5f+IpD+wvHyX35lKQHVCV4Or9k4NP/7y3YbyMMO5w5oqHj16mBNbMidTJ4g2\nv7CDPFqx1L9C2CC3XSrYfL9GEN+MYqcIEPfwoeAAc9PfLuZrVKSDeeFD7Lk9\nEhZaswUYjOP+2xpBaF9SQB7gA8d1m+hXSxqX4tOnJfblU55WN56PAd46wdrK\n0S8eYtAwPo8xCHnLh8zvYm57bH2ulQ36BhL9BTrYbUf5LujcruB/ssH2ZGOO\nr+vDCHI2B3GGbiJXwBaOWvECBO0SAFXfr5EO4HL8CaCK8+Svq1errrcPACrB\nuZ8D\r\n=V0UN\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDJIQzRk7feDUXFR7W+Ug3jtc8EpBoxuJby/Kb96fAM0wIgANNWqVqjGYdvfny0B8+XsV/QSKqMdeyGLbe/zK3Cn+M="}],"size":2659,"noattachment":false,"key":"/p-timeout/-/p-timeout-3.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-timeout_3.0.0_1552379078684_0.7364890382738132"},"_hasShrinkwrap":false,"readme":"# p-timeout\n\n> Timeout a promise after a specified amount of time\n\n## Install\n\n```sh\nnpm install p-timeout\n```\n\n## Usage\n\n```js\nimport {setTimeout} from 'node:timers/promises';\nimport pTimeout from 'p-timeout';\n\nconst delayedPromise = setTimeout(200);\n\nawait pTimeout(delayedPromise, {\n\tmilliseconds: 50,\n});\n//=> [TimeoutError: Promise timed out after 50 milliseconds]\n```\n\n## API\n\n### pTimeout(input, options)\n\nReturns a decorated `input` that times out after `milliseconds` time. It has a `.clear()` method that clears the timeout.\n\nIf you pass in a cancelable promise, specifically a promise with a `.cancel()` method, that method will be called when the `pTimeout` promise times out.\n\n#### input\n\nType: `Promise`\n\nPromise to decorate.\n\n#### options\n\nType: `object`\n\n##### milliseconds\n\nType: `number`\n\nMilliseconds before timing out.\n\nPassing `Infinity` will cause it to never time out.\n\n##### message\n\nType: `string | Error | false`\\\nDefault: `'Promise timed out after 50 milliseconds'`\n\nSpecify a custom error message or error to throw when it times out:\n\n- `message: 'too slow'` will throw `TimeoutError('too slow')`\n- `message: new MyCustomError('it’s over 9000')` will throw the same error instance\n- `message: false` will make the promise resolve with `undefined` instead of rejecting\n\nIf you do a custom error, it's recommended to sub-class `TimeoutError`:\n\n```js\nimport {TimeoutError} from 'p-timeout';\n\nclass MyCustomError extends TimeoutError {\n\tname = \"MyCustomError\";\n}\n```\n\n##### fallback\n\nType: `Function`\n\nDo something other than rejecting with an error on timeout.\n\nYou could for example retry:\n\n```js\nimport {setTimeout} from 'node:timers/promises';\nimport pTimeout from 'p-timeout';\n\nconst delayedPromise = () => setTimeout(200);\n\nawait pTimeout(delayedPromise(), {\n\tmilliseconds: 50,\n\tfallback: () => {\n\t\treturn pTimeout(delayedPromise(), {milliseconds: 300});\n\t},\n});\n```\n\n##### customTimers\n\nType: `object` with function properties `setTimeout` and `clearTimeout`\n\nCustom implementations for the `setTimeout` and `clearTimeout` functions.\n\nUseful for testing purposes, in particular to work around [`sinon.useFakeTimers()`](https://sinonjs.org/releases/latest/fake-timers/).\n\nExample:\n\n```js\nimport {setTimeout} from 'node:timers/promises';\nimport pTimeout from 'p-timeout';\n\nconst originalSetTimeout = setTimeout;\nconst originalClearTimeout = clearTimeout;\n\nsinon.useFakeTimers();\n\n// Use `pTimeout` without being affected by `sinon.useFakeTimers()`:\nawait pTimeout(doSomething(), {\n\tmilliseconds: 2000,\n\tcustomTimers: {\n\t\tsetTimeout: originalSetTimeout,\n\t\tclearTimeout: originalClearTimeout\n\t}\n});\n```\n\n#### signal\n\nType: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\nYou can abort the promise using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).\n\n*Requires Node.js 16 or later.*\n\n```js\nimport pTimeout from 'p-timeout';\nimport delay from 'delay';\n\nconst delayedPromise = delay(3000);\n\nconst abortController = new AbortController();\n\nsetTimeout(() => {\n\tabortController.abort();\n}, 100);\n\nawait pTimeout(delayedPromise, {\n\tmilliseconds: 2000,\n\tsignal: abortController.signal\n});\n```\n\n### TimeoutError\n\nExposed for instance checking and sub-classing.\n\n## Related\n\n- [delay](https://github.com/sindresorhus/delay) - Delay a promise a specified amount of time\n- [p-min-delay](https://github.com/sindresorhus/p-min-delay) - Delay a promise a minimum amount of time\n- [p-retry](https://github.com/sindresorhus/p-retry) - Retry a promise-returning function\n- [More…](https://github.com/sindresorhus/promise-fun)\n","publish_time":1552379078809,"_cnpm_publish_time":1552379078809,"dist-tags":{"latest":"8.1.0"}}