From 840f42813d13d86085bb75ebad8f4a618a9c01d3 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 2 Dec 2018 12:08:26 -0500 Subject: [PATCH 1/2] fs: simplify fs.promises warning logic fs.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. --- lib/fs.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 2e4bdc89647aac..1a720f618189fd 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -86,12 +86,11 @@ const { validateUint32 } = require('internal/validators'); -let promisesWarn = true; let truncateWarn = true; let fs; // Lazy loaded -let promises; +let promises = null; let watchers; let ReadFileContext; let ReadStream; @@ -1931,9 +1930,8 @@ Object.defineProperties(fs, { configurable: true, enumerable: false, get() { - if (promisesWarn) { + if (promises === null) { promises = require('internal/fs/promises'); - promisesWarn = false; process.emitWarning('The fs.promises API is experimental', 'ExperimentalWarning'); } From 93f872c1574fe317149df7ef423bd059e88af9b3 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 2 Dec 2018 12:25:39 -0500 Subject: [PATCH 2/2] 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. --- lib/dns.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/dns.js b/lib/dns.js index ac3f6d6f0ec725..f68409f2ee6743 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -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) { @@ -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); } @@ -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'); }