Skip to content

Commit

Permalink
dns: simplify dns.promises warning logic
Browse files Browse the repository at this point in the history
dns.promises is lazy loaded. Instead of using a seaparate
Boolean flag to track whether or not it has been loaded, just
inspect the state of the lazy loaded module itself.

PR-URL: nodejs#24788
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: Masashi Hirano <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
  • Loading branch information
cjihrig authored and refack committed Jan 10, 2019
1 parent a5a02da commit 1b814f9
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ const {

const dnsException = errors.dnsException;

let promisesWarn = true;
let promises; // Lazy loaded
let promises = null; // Lazy loaded

function onlookup(err, addresses) {
if (err) {
Expand Down Expand Up @@ -269,7 +268,7 @@ function defaultResolverSetServers(servers) {
setDefaultResolver(resolver);
bindDefaultResolver(module.exports, Resolver.prototype);

if (promises !== undefined)
if (promises !== null)
bindDefaultResolver(promises, promises.Resolver.prototype);
}

Expand Down Expand Up @@ -318,10 +317,9 @@ Object.defineProperties(module.exports, {
configurable: true,
enumerable: false,
get() {
if (promisesWarn) {
if (promises === null) {
promises = require('internal/dns/promises');
promises.setServers = defaultResolverSetServers;
promisesWarn = false;
process.emitWarning('The dns.promises API is experimental',
'ExperimentalWarning');
}
Expand Down

0 comments on commit 1b814f9

Please sign in to comment.