mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 05:38:47 +02:00
lib: make ERM functions into wrappers returning undefined
PR-URL: https://github.com/nodejs/node/pull/58400 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
c3b580d9f0
commit
6c9a7cd61e
11 changed files with 34 additions and 20 deletions
|
@ -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])`
|
||||
|
||||
|
@ -6757,7 +6758,8 @@ added: v24.1.0
|
|||
|
||||
> 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]()`
|
||||
|
||||
|
@ -6767,7 +6769,7 @@ added: v24.1.0
|
|||
|
||||
> Stability: 1 - Experimental
|
||||
|
||||
An alias for `dir.closeSync()`.
|
||||
Calls `dir.closeSync()` and returns `undefined`.
|
||||
|
||||
### Class: `fs.Dirent`
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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,
|
||||
|
@ -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() {
|
||||
|
@ -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,
|
||||
|
|
|
@ -273,7 +273,7 @@ class FileHandle extends EventEmitter {
|
|||
};
|
||||
|
||||
async [SymbolAsyncDispose]() {
|
||||
return this.close();
|
||||
await this.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3340,7 +3340,7 @@ class Http2Server extends NETServer {
|
|||
}
|
||||
|
||||
async [SymbolAsyncDispose]() {
|
||||
return promisify(super.close).call(this);
|
||||
await promisify(super.close).call(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,10 @@ const {
|
|||
validateString,
|
||||
validateUint32,
|
||||
} = require('internal/validators');
|
||||
const { kEmptyObject } = require('internal/util');
|
||||
const {
|
||||
assignFunctionName,
|
||||
kEmptyObject,
|
||||
} = require('internal/util');
|
||||
const {
|
||||
inspect,
|
||||
getStringWidth,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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))),
|
||||
);
|
||||
};
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue