Skip to content
Merged
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: 5 additions & 3 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,8 @@ added:

> Stability: 1 - Experimental

An alias for `filehandle.close()`.
Calls `filehandle.close()` and returns a promise that fulfills when the
filehandle is closed.

### `fsPromises.access(path[, mode])`

Expand Down Expand Up @@ -6757,7 +6758,8 @@ added: REPLACEME

> Stability: 1 - Experimental

An alias for `dir.close()`.
Calls `dir.close()` and returns a promise that fulfills when the
dir is closed.

#### `dir[Symbol.Dispose]()`

Expand All @@ -6767,7 +6769,7 @@ added: REPLACEME

> Stability: 1 - Experimental

An alias for `dir.closeSync()`.
Calls `dir.closeSync()` and returns `undefined`.

### Class: `fs.Dirent`

Expand Down
2 changes: 1 addition & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ Server.prototype.close = function close() {
};

Server.prototype[SymbolAsyncDispose] = assignFunctionName(SymbolAsyncDispose, async function() {
return promisify(this.close).call(this);
await promisify(this.close).call(this);
});

Server.prototype.closeAllConnections = function closeAllConnections() {
Expand Down
2 changes: 1 addition & 1 deletion lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ Socket.prototype[SymbolAsyncDispose] = async function() {
if (!this[kStateSymbol].handle) {
return;
}
return FunctionPrototypeCall(promisify(this.close), this);
await FunctionPrototypeCall(promisify(this.close), this);
};


Expand Down
2 changes: 1 addition & 1 deletion lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Server.prototype.close = function close() {
};

Server.prototype[SymbolAsyncDispose] = async function() {
return FunctionPrototypeCall(promisify(this.close), this);
await FunctionPrototypeCall(promisify(this.close), this);
};

/**
Expand Down
17 changes: 12 additions & 5 deletions lib/internal/fs/dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const {
} = require('internal/errors');

const { FSReqCallback } = binding;
const internalUtil = require('internal/util');
const {
assignFunctionName,
promisify,
} = require('internal/util');
const {
getDirent,
getOptions,
Expand Down Expand Up @@ -59,9 +62,9 @@ class Dir {
validateUint32(this.#options.bufferSize, 'options.bufferSize', true);

this.#readPromisified = FunctionPrototypeBind(
internalUtil.promisify(this.#readImpl), this, false);
promisify(this.#readImpl), this, false);
this.#closePromisified = FunctionPrototypeBind(
internalUtil.promisify(this.close), this);
promisify(this.close), this);
}

get path() {
Expand Down Expand Up @@ -304,12 +307,16 @@ ObjectDefineProperties(Dir.prototype, {
[SymbolDispose]: {
__proto__: null,
...nonEnumerableDescriptor,
value: Dir.prototype.closeSync,
value: assignFunctionName(SymbolDispose, function() {
this.closeSync();
}),
},
[SymbolAsyncDispose]: {
__proto__: null,
...nonEnumerableDescriptor,
value: Dir.prototype.close,
value: assignFunctionName(SymbolAsyncDispose, function() {
this.close();
}),
},
[SymbolAsyncIterator]: {
__proto__: null,
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class FileHandle extends EventEmitter {
};

async [SymbolAsyncDispose]() {
return this.close();
await this.close();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -3319,7 +3319,7 @@ class Http2Server extends NETServer {
}

async [SymbolAsyncDispose]() {
return promisify(super.close).call(this);
await promisify(super.close).call(this);
}
}

Expand Down
9 changes: 7 additions & 2 deletions lib/internal/readline/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ const {
validateString,
validateUint32,
} = require('internal/validators');
const { kEmptyObject } = require('internal/util');
const {
assignFunctionName,
kEmptyObject,
} = require('internal/util');
const {
inspect,
getStringWidth,
Expand Down Expand Up @@ -1637,7 +1640,9 @@ class Interface extends InterfaceConstructor {
return this[kLineObjectStream];
}
}
Interface.prototype[SymbolDispose] = Interface.prototype.close;
Interface.prototype[SymbolDispose] = assignFunctionName(SymbolDispose, function() {
this.close();
});

module.exports = {
Interface,
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,13 @@ Readable.prototype[EE.captureRejectionSymbol] = function(err) {
this.destroy(err);
};

Readable.prototype[SymbolAsyncDispose] = function() {
Readable.prototype[SymbolAsyncDispose] = async function() {
let error;
if (!this.destroyed) {
error = this.readableEnded ? null : new AbortError();
this.destroy(error);
}
return new Promise((resolve, reject) => eos(this, (err) => (err && err !== error ? reject(err) : resolve(null))));
await new Promise((resolve, reject) => eos(this, (err) => (err && err !== error ? reject(err) : resolve(null))));
};

// Manually shove something into the read() buffer.
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1149,13 +1149,13 @@ Writable.toWeb = function(streamWritable) {
return lazyWebStreams().newWritableStreamFromStreamWritable(streamWritable);
};

Writable.prototype[SymbolAsyncDispose] = function() {
Writable.prototype[SymbolAsyncDispose] = async function() {
let error;
if (!this.destroyed) {
error = this.writableFinished ? null : new AbortError();
this.destroy(error);
}
return new Promise((resolve, reject) =>
await new Promise((resolve, reject) =>
eos(this, (err) => (err && err.name !== 'AbortError' ? reject(err) : resolve(null))),
);
};
2 changes: 1 addition & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -2395,7 +2395,7 @@ Server.prototype[SymbolAsyncDispose] = async function() {
if (!this._handle) {
return;
}
return FunctionPrototypeCall(promisify(this.close), this);
await FunctionPrototypeCall(promisify(this.close), this);
};

Server.prototype._emitCloseIfDrained = function() {
Expand Down
Loading