{"name":"p-timeout","version":"5.0.2","description":"Timeout a promise after a specified amount of time","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-timeout.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":">=12"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","timeout","error","invalidate","async","await","promises","time","out","cancel","bluebird"],"devDependencies":{"ava":"^3.15.0","delay":"^5.0.0","in-range":"^3.0.0","p-cancelable":"^2.1.0","time-span":"^4.0.0","tsd":"^0.14.0","xo":"^0.38.2"},"gitHead":"0c28612eaefffd76453244e7f6c5ddafcd5d92e1","bugs":{"url":"https://github.com/sindresorhus/p-timeout/issues"},"homepage":"https://github.com/sindresorhus/p-timeout#readme","_id":"p-timeout@5.0.2","_nodeVersion":"16.10.0","_npmVersion":"7.20.3","dist":{"integrity":"sha512-sEmji9Yaq+Tw+STwsGAE56hf7gMy9p0tQfJojIAamB7WHJYJKf1qlsg9jqBWG8q9VCxKPhZaP/AcXwEoBcYQhQ==","shasum":"d12964c4b2f988e15f72b455c2c428d82a0ec0a0","tarball":"http://registry-npm.ywwl.com/p-timeout/download/p-timeout-5.0.2.tgz","fileCount":5,"unpackedSize":9210,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh22HdCRA9TVsSAnZWagAArKsP/R835Xi8MaeHtQlcIUCC\nLPFsEJpztsB1lkXkR0uGIj3uUQD1TojcY4JqligCp9jj4Ia78GOCmHHiOiGs\nwlu7tYW2OZl1Q52uQVIvCSsYccmYpNMOy2Em6k/fRGy0nl8LsNsWORx4zw5y\nXgYtz24SYX7Z07rtMnd0RRVo8hhfSfdC3Wl/5B0Ov9/q01+KxMA/CBfFNJhs\naL3P5sAPpkAeG3nqA2u0V25zCwfHPX6jP7ZYlZNvMMCfzwHzQhkzNEjVpND+\nwyVKTvsREYq994EuusE+eJSwTXiTd0cSRnh1u2IoAF5KIsUdsxA4GAUHU8Ok\nMw0M8cLkoFvS0RxKm1WMdcoFVAY6fPEcDkFM/4GcU9lI7F7bkSfID00oYVeh\n2MsQ4RdevwnNnK/sihiYweXP45lemhqphnCqhX45AoWGOsAj8Lhl0DVNqGHz\na98Q7Oa+52IirpY+dcWjV0OkuVtifn6lgfqUbLtk/+Gj+kC326MHlOkagdNa\nkRBAeiDdEOJA9S/I+rBeYi47p4FIILTIbGNzEp3YsJ8OPfE+VLnWEQW2B2rY\nE1m9519rYN7T2kh8fe8IYk5WHddiEP/3FbC0roAMNNwZlt8lxkYGUY/BBF8d\nn5dQQFSq2K9vx9q1hKiKEza847aRQ2q3ETmokOi4EHxnm+Zke5rDe1OV0rBN\nSHfq\r\n=1bKY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDkY1JH3AZUtgrmEjPTwoGE9iNxal3X44wWOOZXfmy87gIhAJLtqAP9lULzNEVG8ypY+8kLkqFII9QnqEq3fyK0W9B3"}],"size":3093,"noattachment":false,"key":"/p-timeout/-/p-timeout-5.0.2.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-timeout_5.0.2_1634997684443_0.13615090779336492"},"_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":1634997684635,"_cnpm_publish_time":1634997684635,"dist-tags":{"latest":"8.1.0"}}