{"name":"p-timeout","version":"4.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":"https://sindresorhus.com"},"engines":{"node":">=10"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","timeout","error","invalidate","async","await","promises","time","out","cancel","bluebird"],"devDependencies":{"ava":"^2.4.0","delay":"^4.4.0","p-cancelable":"^2.0.0","tsd":"^0.13.1","xo":"^0.35.0"},"gitHead":"bddde181244d185bbf218a5dc18463ded619734d","bugs":{"url":"https://github.com/sindresorhus/p-timeout/issues"},"homepage":"https://github.com/sindresorhus/p-timeout#readme","_id":"p-timeout@4.0.0","_nodeVersion":"10.22.1","_npmVersion":"6.14.9","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"integrity":"sha512-G02ZnMbmDL84Aue/AApFAyP7gaK7PFU2v9xFqUp10y9g1CJ05OVpQjylwYNNCwyVW051rpU8F450Zi2fEV8hVw==","shasum":"4a4ec6a8cc0d5f02db4a6462ac1c14db1e8f8c32","tarball":"http://registry-npm.ywwl.com/p-timeout/download/p-timeout-4.0.0.tgz","fileCount":5,"unpackedSize":8880,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfxmezCRA9TVsSAnZWagAAlCoP/1ZSmOV0J66tjkA4C+9j\n8+tdeCZffHyb6MIs6y0uiwSvwL2YWrrrBiBNVaDobY90Vd42CjkwPmtTJ9Xb\nnBeFMHPNTWMh1bPQQMyY+kNvhASjzFZKgvChm26Zl3NiLQ+MayAYkBWEf2OD\n2bcR89Kn5zfltCl0Nf7MU2qdl0/GpRNmwEw8kyycic/NoyKildfAAuaekedK\n/Nqd9w4OK0qV1iAUwPuZO5L3yq5AbsbIy9153At304hregPNujpMASu7mgK6\n3mGTQbAVwempIn8EBj2T+DoIaGMtUJ83XIDHcw8ZfR/olDCvspUgNM1Sf/6n\ntv8irWCzTLxsMrzKfNgrVR4gLVXUziGkkoYNOAluUFLIP7iV3oSbZKDtVMWF\n6vyF1QXnEpssv5LZAP1/pIoHs/i7lxNyqfmrJb5utx4OhW4s1jx26vkTYVv0\nRcInSPlS16Nw3izLIg+HyTLtyQOHqokc/1QIZO04KS0Osgfo5eC2OEun8XSr\n7WNnyNIWE29dgFhue3nddGu3WXs8iAy/sz303d6Xhl1HBhuTIZh0uqmKccIx\nK/KpvfExHk2pGC//nVyAN87ARwr7cgk1VH20wuVjFmLb6M5DNPjG+Vy8xacg\nYkMuOEai3fVSvP0pkrHmllezEVBPORnYzIGI1OSGYATZzjDsyGrSLZS6uP7k\nM3Ha\r\n=pFhd\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCslLO+HxBWCl9TZJU+scS16CH9pOnMfDAQOZK1yERe5QIhAI4G1Z44zBngwkIcaLfynip4sZ/d07hn6althHYvwF1c"}],"size":3072,"noattachment":false,"key":"/p-timeout/-/p-timeout-4.0.0.tgz"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-timeout_4.0.0_1606838195237_0.8859125444067344"},"_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":1606838195402,"_cnpm_publish_time":1606838195402,"dist-tags":{"latest":"8.1.0"}}