{"name":"guard-timeout","version":"1.0.1","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":"7934551369342d7ad63cb9c12b6f0f7a6cc9a6f9","_id":"guard-timeout@1.0.1","_nodeVersion":"12.14.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-ouuu3ITED2bFeSzxnUFOdeVUuinXocVUchEx/S7r34Nmf2t77T2lOGw6mE0Zx4WhmmGr3PcBxovexuGv1rbKEQ==","shasum":"3f45490a49fbb3452ced3b39287c493d3d9d40fc","tarball":"http://registry-npm.ywwl.com/guard-timeout/download/guard-timeout-1.0.1.tgz","fileCount":7,"unpackedSize":11113,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeXT8PCRA9TVsSAnZWagAAi6IP/2ASRjV6aXXDndF1+Wq2\neFjZ3hhCgZD+/slW+UL6N+N1STXLvXeGCw2SJdcdF6XMAoJSDfLFpCVMOQd4\nnIzsg7jlY1yXthjap9w2bhaytA1/V52xM+CB07lfaBEEd4JI90ohMqX+shgL\nV+roCzpvzXFQ6I/uGG/v2Dusdcckf4ZlL/NHa/plJt9IQe4WQgBvFFmWVZ5/\n4Obw8CPP8Ls/MNoJUpTHEjbIWbKvq9C0kqkj1QtmnJzekjv1ayBkHVVCdc2O\nZ/kjUiPKc+2N8iGEzp4J3KNJ+mKt3OgiqbUfiUhQm6dciHXBaNPmLcW+sU3s\nRoy94OPoeXImbhkyhh0RzZfbp8qUhH6vCRUZhVBbk99qn2n8KcWsqfmSxUZ8\nwlsrbWw/IIZrtzaKSVmsOLzrUOaquYw3ykGmLInTqPlw3VHYRplw63uPhjPG\nR+RhnxBXNqNdx49qbnKnEEtTgItdC/VInQ9SY0hLbuJ1N8NwqjvJX8xZXACm\nfrRjPZ8vjeX5PaXoZUdiroy82hORSO4f2d4T+fczkW5qv7oCcB1uVb4/KJoF\nlrzU6LrmDa/ZEB6EqXXxzuk7fTgyCDzo9wn+oO9m/5Q3+BBb4qAYEjxaSUqg\nxt51HuVd8bCArg5jcjlYX1eZCgHGgR4MBdbYKWuWkiI22ohvhkHDSf2aD5Or\n1QqI\r\n=CCVn\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEMCH1UxkEngKedROvXk7cBAZHKXq9LlDBfhO3tBZBpgMGUCIAE/V1yGfWhHOuXSNyaTz8zFxLTwJ/HLllzXKqK2wBge"}],"size":4161,"noattachment":false,"key":"/guard-timeout/-/guard-timeout-1.0.1.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.1_1583169294866_0.18918230468616715"},"_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":1583169295022,"_cnpm_publish_time":1583169295022,"dist-tags":{"latest":"2.0.0"}}