From 8af4f4413030f6b3b75d1c567857aa873fb97fda Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 2 Dec 2018 12:25:39 -0500 Subject: [PATCH] dns: simplify dns.promises warning logic 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: https://github.com/nodejs/node/pull/24788 Reviewed-By: Anto Aravinth Reviewed-By: Weijia Wang Reviewed-By: Masashi Hirano Reviewed-By: Jeremiah Senkpiel --- lib/dns.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/dns.js b/lib/dns.js index b2ae92a9d6999c..f90d7c1a57b541 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -49,8 +49,7 @@ const { const dnsException = errors.dnsException; -let promisesWarn = true; -let promises; // Lazy loaded +let promises = null; // Lazy loaded function onlookup(err, addresses) { if (err) { @@ -267,7 +266,7 @@ function defaultResolverSetServers(servers) { setDefaultResolver(resolver); bindDefaultResolver(module.exports, Resolver.prototype); - if (promises !== undefined) + if (promises !== null) bindDefaultResolver(promises, promises.Resolver.prototype); } @@ -316,10 +315,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'); }