{"name":"p-timeout","version":"5.1.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"},"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"},"types":"./index.d.ts","gitHead":"56e22052c6e59eb694fcc90020fe8f5124818327","bugs":{"url":"https://github.com/sindresorhus/p-timeout/issues"},"homepage":"https://github.com/sindresorhus/p-timeout#readme","_id":"p-timeout@5.1.0","_nodeVersion":"16.15.0","_npmVersion":"8.3.2","dist":{"integrity":"sha512-auFDyzzzGZZZdHz3BtET9VEz0SE/uMEAx7uWfGPucfzEwwe/xH0iVeZibQmANYE/hp9T2+UUZT5m+BKyrDp3Ew==","shasum":"b3c691cf4415138ce2d9cfe071dba11f0fee085b","tarball":"http://registry-npm.ywwl.com/p-timeout/download/p-timeout-5.1.0.tgz","fileCount":5,"unpackedSize":11328,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCkFZ73YKeEX5ZhC1P5mDVNpwkndP6K06PWzq6lPmGbGgIgZDfQAAN03WO5u6q5h3WaqPuotrL5Fhn9iJcwALPAa1w="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJij7hSACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoJdA/+JFMTSP7fwjCMTxm0T/ttj4cNmJ4UlQqAQj+vpDdMlEOAAqX5\r\n6EWCiSoItqMFBL2TeXTaaZlVm8i9VcixRKtcFvBunIn9jDH+sCWGtELZajSs\r\n3nXtKp5K5oHJ2jwo0ImVJ9rw2xaUbZKclhBLJ7X/dNcwUnTo4shxWnrI/jC9\r\nR8yUZzscYul9Qvt1YsuJ2y7K4JXTzB0uM+4H1dvHicLh1xmLVxoNXMioODLQ\r\n2KNTZiau2r7UC20mrcFsKEP3iSNxBdrB+M3xV2luuRMt5hT9wsz8x9pCZx5I\r\niTumpXHK82siw64H/9vL4VqLSeZrgRA9gxrnFt/eUgfY0OOQCzSfBnEt5Ph/\r\nXPCogUmnZA+M7KFnsDXf/RzXHK23Z/S7OOIM8XD4Nltigy+SuCwZobLtrri4\r\nOlKGEvRhisv4lljmOwhru1BTeJZYpp1Z09redXLmzyq2C/fj4pp0X47Mvj6W\r\nrNB4QzKbquxF2I4TZhFIV5/3xVVCF2Z+XcXvC7kLxA1n8HR28Em8j72wFA7z\r\ntjbDqJLEycWXyEcfmuztav3UwaPcNN2ADKesqSQv0rFfkmNlPc7yEMGfw1WX\r\n+FhX9C7LZvbkOnPWdWjlSzF8wEsu0/U6jW4zIeqdHnvjR7oBuFCzq+VvwujY\r\n+SHAxnfvV08aniqq+jp65sSN/AqyZgK3K9U=\r\n=arm/\r\n-----END PGP SIGNATURE-----\r\n","size":3637,"noattachment":false,"key":"/p-timeout/-/p-timeout-5.1.0.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.1.0_1653586002488_0.7270644693104262"},"_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":1653586002627,"_cnpm_publish_time":1653586002627,"dist-tags":{"latest":"8.1.0"}}