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: #24788
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Masashi Hirano <shisama07@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
cjihrig authored and BridgeAR committed Dec 5, 2018
1 parent 124fca0 commit 2dfaa48
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 2dfaa48

Please sign in to comment.