net: server add asyncDispose

PR-URL: https://github.com/nodejs/node/pull/48717
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
atlowChemi 2023-07-10 00:22:05 +03:00 committed by Node.js GitHub Bot
parent 17f6b8c49c
commit 0e9138d173
3 changed files with 51 additions and 1 deletions

View file

@ -28,6 +28,7 @@ const {
ArrayPrototypePush,
Boolean,
FunctionPrototypeBind,
FunctionPrototypeCall,
MathMax,
Number,
NumberIsNaN,
@ -35,6 +36,7 @@ const {
ObjectDefineProperty,
ObjectSetPrototypeOf,
Symbol,
SymbolAsyncDispose,
SymbolDispose,
} = primordials;
@ -112,7 +114,7 @@ const {
} = require('internal/errors');
const { isUint8Array } = require('internal/util/types');
const { queueMicrotask } = require('internal/process/task_queues');
const { kEmptyObject, guessHandleType } = require('internal/util');
const { kEmptyObject, guessHandleType, promisify } = require('internal/util');
const {
validateAbortSignal,
validateBoolean,
@ -2243,6 +2245,13 @@ Server.prototype.close = function(cb) {
return this;
};
Server.prototype[SymbolAsyncDispose] = async function() {
if (!this._handle) {
return;
}
return FunctionPrototypeCall(promisify(this.close), this);
};
Server.prototype._emitCloseIfDrained = function() {
debug('SERVER _emitCloseIfDrained');