{"_id":"guard-timeout","_rev":"4-5f79c0475de7a8e792d4493634398844","name":"guard-timeout","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0":{"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":"https://registry.npmjs.org/guard-timeout/-/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="}]},"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},"1.0.1":{"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":"https://registry.npmjs.org/guard-timeout/-/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"}]},"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},"1.0.2":{"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":"https://registry.npmjs.org/guard-timeout/-/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=="}]},"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},"2.0.0":{"name":"guard-timeout","version":"2.0.0","description":"Guard against sleep mode timeouts firing on wake","main":"index.js","browser":{"util":"./util-shim.js"},"scripts":{"test":"tape test/*","btest":"airtap --local test","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","atomic-sleep":"^1.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":"cef8ed8828c6270dffc41e4e966c72369ac4fc02","_id":"guard-timeout@2.0.0","_nodeVersion":"12.16.1","_npmVersion":"6.13.4","dist":{"integrity":"sha512-35geHv72oal0cRUE5t1tZ5KHm3OVPXzFtiMG8AnRPV5FkkEf84RUpeQ0BCeCZunfSLGATW5ZVyALhJKgM7I/6A==","shasum":"7f8f1f6d09bdeb6d0fee4cbd743d593c14d7d78a","tarball":"https://registry.npmjs.org/guard-timeout/-/guard-timeout-2.0.0.tgz","fileCount":7,"unpackedSize":9973,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeciWPCRA9TVsSAnZWagAAEM8P/iDBjBs7yG5/I76LqMJC\nIKYV/FrqCc/0DTy/8+ANQESEA9EoO0cCkViXteqcUQY+SfJvVhP/u7Ql3nNF\nEzA+I4psABuAIb7w0+VEWoc2axmOKWGYHCrjjBPzqPo33sZrJhAua2NqdsIR\nLZ7MkJvCWq62GmnIrGgjByLjTKtDxKITvkU1ZkYM0PM3YhJbj9fMAAlI4OFn\nrQYI6h74SOeVjQmMtujaCFoGGjeZkh+ywHu+i1gI7axUMX4Fztqvw+yTfMAQ\nLPHP7vrWD9KDS6GYOBGQouNDSr9awE28d5e+qkNH7UYcXH2wz9O0n7AHHBcM\nRYatko2uZQItG53MaajqqU1GiFvWVAFvGh82HwHDysAXvr2goTD87GyQKziw\nm8WMhZhUONWliU2zsnWBRfOwrkYTgxvcilXeLHsV95Ane1YlSNh/zu8zgcJr\nNGhUDZ2F8E/y+xFo38p7nn11eZfQVA93RT+vMROYIAcmrljNawFV0KRjgzAR\nxv9ZzvLWF4cXtCISzoTQH8v3CBytLoRO2SjJv79bsN0MXU4GSuIMuOawC1XE\n7Muc+2a/3MECBokWexLw9TD7Q6MHt7FBIoHTKJ56hDTUM/IyjSheoqCRcH5c\nPJOd7AM2BMV/sIEKw0tQiaGEoB/gxhDjIuaxSDWR2srBfiJYJ+B3aRj5ntZK\n/nFK\r\n=JPty\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBF9qx2kKdgGWACj8sQDwcLeZnf0qk5YOAanqi+6sl19AiEA6QA7DCIHBvww09GDr3Nf+P2feUmMJSUDJipg0ss4+8o="}]},"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_2.0.0_1584539022699_0.2789808994198222"},"_hasShrinkwrap":false}},"time":{"created":"2020-02-21T17:29:07.057Z","1.0.0":"2020-02-21T17:29:07.166Z","modified":"2022-05-04T09:16:44.732Z","1.0.1":"2020-03-02T17:14:55.022Z","1.0.2":"2020-03-03T19:46:43.000Z","2.0.0":"2020-03-18T13:43:42.813Z"},"maintainers":[{"name":"davidmarkclements","email":"huperekchuno@googlemail.com"}],"description":"Guard against sleep mode timeouts firing on wake","homepage":"https://github.com/davidmarkclements/guard-timeout#readme","keywords":["timeout","safe","sleep","hibernate"],"repository":{"type":"git","url":"git+https://github.com/davidmarkclements/guard-timeout.git"},"author":{"name":"David Mark Clements","url":"@davidmarkclem"},"bugs":{"url":"https://github.com/davidmarkclements/guard-timeout/issues"},"license":"MIT","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","readmeFilename":"readme.md"}