{"name":"guard-timeout","version":"1.0.2","description":"Guard against sleep mode timeouts firing on wake","main":"index.js","browser":{"util":"./util-shim.js"},"scripts":{"test":"node test","btest":"airtap --local test.js","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":{"airtap":"^3.0.0","standard":"^14.3.1","tape":"^4.13.0"},"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":"3843b913518e944549bddb4104244d3f210588b9","_id":"guard-timeout@1.0.2","_nodeVersion":"12.14.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-pHBSeiEgAFMhZP3dycr5Fgs3NBnuyeELDYhUez9Nd6UDnMp/qkSr3xsXcjx9upfOozGZaassJtgv7nrqwXBlyA==","shasum":"74f04554d59c98be32b6242c7e7172a9092bdede","tarball":"http://registry-npm.ywwl.com/guard-timeout/download/guard-timeout-1.0.2.tgz","fileCount":7,"unpackedSize":11062,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeXrQjCRA9TVsSAnZWagAAe90P/Rbg1bvbRKSAMAl/Hpgf\nLKwXWWModO2C7GzN0rYTtC2S27jYXq/BqwIA9j2BZAYh/ZSEsVu8am60cIwx\ngUIRU94hQr9XhXsz09q2hVMr3Sv1boWrMEfHUe5p5Et8MyAWQR78UNz22vXR\nJKCWCiU9TeE6jY7f882l4QmIrFuQL9pDxMwgO4W8lOHNCXnEhbMCERKQJ79Y\nLGlBTQGnH/Cwy8Hn96toVXCt91iRXZ4dCzkiHmZ2hhQctEGdjNZb1KHqtAyA\nETR0geXLc0+RwUKSyAn3x4oKIRvfyL19xRtpBtxww+qr67gDQT0ezhXD7t/c\nDyxjmivDKRITl95fR8b33WDU07mFSd+dXtsXL8Qoh9Qbz8HbXmYc8JnKDnuF\n9AExWYCaHUFQQlg9RKI5sYR/ZczsvxzwzcUhgwuoMx7Luf9O6TGl4tjpPJUh\naXpRdeGsusEhe3WcMNvjSDvNlyqq8ET2sG3huHUDZcIfVjLCHB5YPrI341Qr\n8jS9eGhB7BdVFnCpFSG4xlre/4j+YacPDUNxDGfkMi9fLffjjZ6NuowW77Fb\nQMlF39/g7iLijnlap+nzkECEWb5RjQcsrWRD3zDqmbK4wkJZKaA67S7M4Teu\ncF3SvjxZ4LMWUk+7Z7R8ulr0vJVISuxllFLIbILIMEGJynbVYw5ujofV0rp5\nYQzJ\r\n=FCXe\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICyNe1oeO2EPxNhB25u2nUjVq2ggdIng9BHZif98i67hAiATRpcHDOVe/qX89tTum6ijenW2DKCyxs4hsJDFkscOxw=="}],"size":4143,"noattachment":false,"key":"/guard-timeout/-/guard-timeout-1.0.2.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.2_1583264802873_0.08578602958778392"},"_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":1583264803000,"_cnpm_publish_time":1583264803000,"dist-tags":{"latest":"2.0.0"}}