{"name":"guard-timeout","version":"1.0.0","description":"Guard against sleep mode timeouts firing on wake","main":"index.js","scripts":{"test":"tap -R classic","cov":"npm test -- --coverage-report=html","lint":"standard","ci":"npm run lint && npm test"},"keywords":["timeout","safe","sleep","hibernate"],"author":{"name":"David Mark Clements","url":"@davidmarkclem"},"license":"MIT","engineStrict":true,"engines":{"node":">=10"},"devDependencies":{"tap":"^14.10.6"},"repository":{"type":"git","url":"git+https://github.com/davidmarkclements/guard-timeout.git"},"bugs":{"url":"https://github.com/davidmarkclements/guard-timeout/issues"},"homepage":"https://github.com/davidmarkclements/guard-timeout#readme","gitHead":"49763f1896b117a9031fd5a3a6e011e1a530ea79","_id":"guard-timeout@1.0.0","_nodeVersion":"12.14.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-Y75KJiLp6JMz8VyPVmn9fIg2+dStuBi3p+UtrSEOpP6wOIr4UkpfPi1ibWceKzu5fPfytsqH1ON2oDbIb1FufQ==","shasum":"6897750526ec45800dde9ed0864e21fc188d85a8","tarball":"http://registry-npm.ywwl.com/guard-timeout/download/guard-timeout-1.0.0.tgz","fileCount":6,"unpackedSize":9734,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeUBNjCRA9TVsSAnZWagAAgQsP/0AQgWY9FseNiDMy2NmC\nNieDAS8gg3jPJSkt/hl76N+T1U3pZCOXQepoiQR/c7yRvJndrTCbf7w4XtNQ\nzhmsWH30nk9NoH5P/ZVjho9RXBwOuSZ2udV5VMDj3O0cJTMLzkf3jE1EOqP7\njHWWjaSkif7zfKFh0Bm8oc+SXtHney+7SuVhPwdgIDMIJEFl0dUtMU3jgYMY\nxx8Z7ATdTlD2upLXJ/u4c9S3faqsK/UuA8IsI6l08OZs4aOwzDqqED8LfBRv\nwepEph/5dXr+Gh1q9JONGzaGBf2YDI1T2FOXQN5bdvGKr44zhYZJt0QJzOXi\nIsr0mHt1XwKuQ3ipdv86qhgJvVNYi552UKkeohofg2e3za9JZsbNQ2XnnU7t\nLC1B+CANZBDvMhEEwU4nyOTQZs7o4ULMMVt9loSKE5T51TSLtLZRd9Z7tns2\nQ4qaNPjgOT1cGkGwGZeE/7hacBtBLZDzsR40G0jwe0riNM17ADjj1+zDmTdo\n+SeZ+3Aw9FDucJ4gCTQN01oQgfRDo65claiAXOKybNBuopwibPZcL6WCVlFG\n40vl4ChsyZWFtkY6U9iEwtqZUbRTv+eIdyBbR9kksxV/dWs8XoDe9G5WjxZu\nzoR+T1AoKYi9Vx8VOHYjmekOr8GRvzf5xkkp1cccT6WNYRrSYn9Y1AVuUQMh\nnlX6\r\n=tYVC\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB12BvyNLgxpZoYMiKx+KZWgCmdtxu7Ftn94EiEZap4RAiEAp8r78uHw49FbbFsavk+NOBknB56P4Nf/9DbJU0GTlzo="}],"size":3656,"noattachment":false,"key":"/guard-timeout/-/guard-timeout-1.0.0.tgz"},"maintainers":[{"name":"davidmarkclements","email":"huperekchuno@googlemail.com"}],"_npmUser":{"name":"davidmarkclements","email":"huperekchuno@googlemail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/guard-timeout_1.0.0_1582306147058_0.9239583860859539"},"_hasShrinkwrap":false,"readme":"# guard-timeout\n\n> Guard against sleep mode timeouts firing on wake\n\n## About\n\nIf a process goes into a sleep mode (for instance a laptop hibernates, or a service is put into inspect mode) then timeouts may trigger on wake. Depending on your use case (think distributed systems) you might not want to trigger a timeout if process uptime hasn't actually occurred in that period. \n\nThe `guard-timeout` module will check if there is a significant lag (default 1s) between when the timeout \nwas scheduled to fire and when it actually fired. \n\n\n## Install\n\n```sh\n$ npm i guard-timeout\n```\n\n## Usage\n\n```js\nconst setTimeout = require('guard-timeout')\n\n// if the timeout is 1 second late, \n// it will be reschedule for another 20 minutes\n\nsetTimeout(\n  () => { console.log('do something') }, \n  1.2e+6 // 20 minutes\n)\n```\n\n## Advanced Usage\n\nConfigure your own safe timeout: \n\n```js\nconst setTimeout = require('guard-timeout').create({\n  lagMs: 60 * 1000 // 1 minute lag\n})\n\n// if the timeout is 1 minute late, \n// it will be reschedule for another 20 minutes\n\nsetTimeout(\n  () => { console.log('do something') }, \n  1.2e+6 // 20 minutes\n)\n```\n\n## Await Usage\n\n`guard-timeout` has [`util.promisify`](https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original) support: \n\n```js\nconst { promisify } = require('util')\nconst timeout = promisify(require('guard-timeout'))\n\nasync function run () {\n  // if the timeout is 1 second late, \n  // it will be reschedule for another 20 minutes\n  await timeout(1.2e+6) // 20 minutes\n  console.log('do something')\n}\n\nrun().catch(console.error)\n```\n\n## API\n\n### `require('guard-timeout') => setTimeout (cb, time, ...args) => instance`\n\nThe default export of `guard-timeout` a is safe `setTimeout` function with a \ndefault `lagMs` option of 1000 (one second).\n\n### `require('guard-timeout').create(opts) => setTimeout (cb, time, ...args) => instance`\n\nCreate a custom safe `setTimeout` function by passing in options\n\n### `instance.close()`\n\nClears the timeout\n\n### `instance.timeout`\n\nA getter property which holds current underlying timeout object (or numerical ID in the browser).\n\n\n\n#### Options\n\n*  `lagMs` – `Number`, default: 1000. The allowable delta between when a timeout should fire and when it actually fires, in milliseconds. If this is exceeded then the timeout is rescheduled.\n* `rescheduler` - `Function`, default: `(t, instance) => t`. A mapping function to calculate when the timeout should be rescheduled for. It takes two args, the time that the timeout was scheduled for and the timeout instance returned from `guard-timeout` (which comes Node's native `setTimeout`). The `instance` argument can be used to apply specific reschedule times to specific timeouts. The return value should be a number representing milliseconds for the rescheduled timeout. \n\n\n## Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/David%20Mark%20Clements/guard-timeout/issues)\n\n## Author\n\n**David Mark Clements**\n\n* [github/davidmarkclements](https://github.com/davidmarkclements)\n* [twitter/davidmarkclem](http://twitter.com/davidmarkclem)\n\n## License\n\nCopyright © 2020 David Mark Clements\nLicensed under the MIT license.\n","publish_time":1582306147166,"_cnpm_publish_time":1582306147166,"dist-tags":{"latest":"2.0.0"}}