cacheable-lookup
Advanced tools
Comparing version 4.2.0 to 4.2.1
{ | ||
"name": "cacheable-lookup", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"description": "A cacheable dns.lookup(…) that respects the TTL", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -89,3 +89,3 @@ # cacheable-lookup | ||
The time how long it needs to remember failed queries (TTL in seconds). | ||
The time how long it needs to remember queries that threw `ENOTFOUND` (TTL in seconds). | ||
@@ -92,0 +92,0 @@ **Note**: This option is independent, `options.maxTtl` does not affect this. |
'use strict'; | ||
const {watchFile} = require('fs'); | ||
const {readFile} = require('fs').promises; | ||
const {readFile, stat} = require('fs').promises; | ||
const {isIP} = require('net'); | ||
@@ -20,2 +19,23 @@ | ||
// TODO: Remove this when https://github.com/nodejs/node/issues/33096 gets fixed | ||
const watchFile = (path, callback, onError) => { | ||
let previousTime = null; | ||
const interval = setInterval(async () => { | ||
try { | ||
const {mtimeMs} = await stat(path); | ||
if (previousTime !== null && mtimeMs !== previousTime) { | ||
callback(mtimeMs, previousTime); | ||
} | ||
previousTime = mtimeMs; | ||
} catch (error) { | ||
clearInterval(interval); | ||
onError(error); | ||
} | ||
}, 1000 * 60).unref(); | ||
}; | ||
class HostsResolver { | ||
@@ -42,2 +62,4 @@ constructor(customHostsPath = hostsPath) { | ||
} | ||
}, error => { | ||
this._error = error; | ||
}); | ||
@@ -44,0 +66,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25023
512
2