{"_id":"function-timeout","_rev":"3518589","name":"function-timeout","description":"Make a synchronous function have a timeout","dist-tags":{"latest":"1.0.2"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2024-08-27T20:52:36.000Z","created":"2022-06-03T09:58:22.569Z","1.0.2":"2024-05-17T17:30:03.940Z","1.0.1":"2023-11-09T19:39:19.141Z","1.0.0":"2023-11-04T13:58:56.733Z","0.1.1":"2022-06-28T23:50:45.701Z","0.1.0":"2022-06-03T09:58:22.569Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/function-timeout.git"},"versions":{"1.0.2":{"name":"function-timeout","version":"1.0.2","description":"Make a synchronous function have a timeout","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/function-timeout.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","node":"./index.js","default":"./browser.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsd"},"keywords":["function","synchronous","timeout","time","out","cancel","expire","abort","regex","regexp","redos","security","func","fn","script","execute","halt","termination"],"devDependencies":{"ava":"^5.3.1","in-range":"^3.0.0","time-span":"^5.1.0","tsd":"^0.29.0","xo":"^0.56.0"},"_id":"function-timeout@1.0.2","gitHead":"12471c7f085b034c3b2432a223376e60173ec43a","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/function-timeout/issues"},"homepage":"https://github.com/sindresorhus/function-timeout#readme","_nodeVersion":"22.1.0","_npmVersion":"10.6.0","dist":{"shasum":"e5a7b6ffa523756ff20e1231bbe37b5f373aadd5","size":2654,"noattachment":false,"key":"/function-timeout/-/function-timeout-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/function-timeout/download/function-timeout-1.0.2.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/function-timeout_1.0.2_1715967003799_0.03519201814812045"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-05-17T17:30:03.940Z","publish_time":1715967003940,"_source_registry_name":"default","_cnpm_publish_time":1715967003940},"1.0.1":{"name":"function-timeout","version":"1.0.1","description":"Make a synchronous function have a timeout","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/function-timeout.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","node":"./index.js","default":"./browser.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsd"},"keywords":["function","synchronous","timeout","time","out","cancel","expire","abort","regex","regexp","redos","security","func","fn","script","execute","halt","termination"],"devDependencies":{"ava":"^5.3.1","in-range":"^3.0.0","time-span":"^5.1.0","tsd":"^0.29.0","xo":"^0.56.0"},"types":"./index.d.ts","gitHead":"dcf1b5c856557450a1122c4dd5f4498d2645001f","bugs":{"url":"https://github.com/sindresorhus/function-timeout/issues"},"homepage":"https://github.com/sindresorhus/function-timeout#readme","_id":"function-timeout@1.0.1","_nodeVersion":"18.18.2","_npmVersion":"9.2.0","dist":{"shasum":"fd379f96501e536617a89ae080d44539ed805f63","size":2650,"noattachment":false,"key":"/function-timeout/-/function-timeout-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/function-timeout/download/function-timeout-1.0.1.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/function-timeout_1.0.1_1699558758958_0.2950830782318752"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-11-09T19:39:19.141Z","publish_time":1699558759141,"_source_registry_name":"default","_cnpm_publish_time":1699558759141},"1.0.0":{"name":"function-timeout","version":"1.0.0","description":"Make a synchronous function have a timeout","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/function-timeout.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","node":"./index.js","default":"./browser.js"},"engines":{"node":">=18"},"scripts":{"test":"xo && ava && tsd"},"keywords":["function","synchronous","timeout","time","out","cancel","expire","abort","regex","regexp","redos","security","func","fn","script","execute","halt","termination"],"devDependencies":{"ava":"^5.3.1","in-range":"^3.0.0","time-span":"^5.1.0","tsd":"^0.29.0","xo":"^0.56.0"},"types":"./index.d.ts","gitHead":"dfc2e4a2a1773a8bc8d53132cfe362d56c5d0739","bugs":{"url":"https://github.com/sindresorhus/function-timeout/issues"},"homepage":"https://github.com/sindresorhus/function-timeout#readme","_id":"function-timeout@1.0.0","_nodeVersion":"18.18.2","_npmVersion":"9.2.0","dist":{"shasum":"a0197b49d669a5add7a56dd67abc517d226f1fe7","size":2544,"noattachment":false,"key":"/function-timeout/-/function-timeout-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/function-timeout/download/function-timeout-1.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/function-timeout_1.0.0_1699106336551_0.8912591252975248"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-11-04T13:58:56.733Z","publish_time":1699106336733,"_source_registry_name":"default","_cnpm_publish_time":1699106336733},"0.1.1":{"name":"function-timeout","version":"0.1.1","description":"Make a synchronous function have a timeout","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/function-timeout.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","node":"./index.js","default":"./browser.js"},"engines":{"node":">=14.16"},"scripts":{"test":"xo && ava && tsd"},"keywords":["function","synchronous","timeout","time","out","cancel","expire","abort","regex","regexp","redos","security","func","fn","script","execute"],"devDependencies":{"ava":"^4.3.0","in-range":"^3.0.0","time-span":"^5.0.0","tsd":"^0.20.0","xo":"^0.49.0"},"types":"./index.d.ts","gitHead":"8bd130c18582a2572680520d96c7046e9be9ef16","bugs":{"url":"https://github.com/sindresorhus/function-timeout/issues"},"homepage":"https://github.com/sindresorhus/function-timeout#readme","_id":"function-timeout@0.1.1","_nodeVersion":"14.19.3","_npmVersion":"8.3.2","dist":{"shasum":"6bf71d3d24c894d43b2bec312cabb8c5add2e9da","size":2535,"noattachment":false,"key":"/function-timeout/-/function-timeout-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/function-timeout/download/function-timeout-0.1.1.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/function-timeout_0.1.1_1656460245514_0.4325109032765051"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-06-28T23:55:19.834Z","publish_time":1656460245701,"_cnpm_publish_time":1656460245701},"0.1.0":{"name":"function-timeout","version":"0.1.0","description":"Make a synchronous function have a timeout","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/function-timeout.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","node":"./index.js","default":"./browser.js"},"engines":{"node":">=14.16"},"scripts":{"test":"xo && ava && tsd"},"keywords":["function","synchronous","timeout","time","out","cancel","expire","abort","regex","regexp","redos","security","func","fn","script","execute"],"devDependencies":{"ava":"^4.3.0","in-range":"^3.0.0","time-span":"^5.0.0","tsd":"^0.20.0","xo":"^0.49.0"},"types":"./index.d.ts","gitHead":"8ee023af773e121d970da212224fe21a3376a1ea","bugs":{"url":"https://github.com/sindresorhus/function-timeout/issues"},"homepage":"https://github.com/sindresorhus/function-timeout#readme","_id":"function-timeout@0.1.0","_nodeVersion":"14.19.2","_npmVersion":"8.3.2","dist":{"shasum":"ddbf013e9ab83bbe170a65589b6a233b0084bfa0","size":2527,"noattachment":false,"key":"/function-timeout/-/function-timeout-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/function-timeout/download/function-timeout-0.1.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/function-timeout_0.1.0_1654250302461_0.9300863745963093"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-06-05T12:49:52.522Z","publish_time":1654250302569,"_cnpm_publish_time":1654250302569}},"readme":"# function-timeout\n\n> Make a synchronous function have a timeout\n\nThis can be useful if you accept external data and want to ensure processing it does not take too long.\n\nThe timeout only works in Node.js. When used in a browser, the function will be wrapped, but never time out.\n\n*I have a [different package](https://github.com/sindresorhus/super-regex) to prevent [ReDoS](https://en.wikipedia.org/wiki/ReDoS) for regexes.*\n\n## Install\n\n```sh\nnpm install function-timeout\n```\n\n## Usage\n\n```js\nimport functionTimeout, {isTimeoutError} from 'function-timeout';\n\nconst generateNumbers = count => {\n\t// Imagine this takes a long time.\n};\n\nconst generateNumbersWithTimeout = functionTimeout(generateNumbers, {timeout: 100});\n\ntry {\n\tconsole.log(generateNumbersWithTimeout(500));\n} catch (error) {\n\tif (isTimeoutError(error)) {\n\t\tconsole.error('Timed out');\n\t} else {\n\t\tthrow error;\n\t}\n}\n```\n\n## API\n\n### functionTimeout(function, options?)\n\nReturns a wrapped version of the given function that throws a timeout error if the execution takes longer than the given timeout.\n\n#### options\n\nType: `object`\n\n##### timeout?\n\nType: `number` *(integer)*\n\nThe time in milliseconds to wait before timing out.\n\nKeep in mind that execution time can vary between different hardware and Node.js versions. Set a generous timeout to avoid flakiness.\n\n### isTimeoutError(error)\n\nReturns a boolean for whether the given error is a timeout error.\n\n## Related\n\n- [super-regex](https://github.com/sindresorhus/super-regex) - Make a regular expression time out if it takes too long to execute\n- [p-timeout](https://github.com/sindresorhus/p-timeout) - Timeout a promise after a certain amount of time\n","_attachments":{},"homepage":"https://github.com/sindresorhus/function-timeout#readme","bugs":{"url":"https://github.com/sindresorhus/function-timeout/issues"},"license":"MIT"}