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 BethGriggs committed Feb 12, 2019
1 parent 576d9c5 commit 8af4f44
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 @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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');
}
Expand Down

0 comments on commit 8af4f44

Please sign in to comment.