Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs, dns: simplify promises warning logic #24788

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 2 additions & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
Expand Down