http2: server add asyncDispose

PR-URL: https://github.com/nodejs/node/pull/48548
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
atlowChemi
2023-06-25 23:19:38 +03:00
committed by Moshe Atlow
parent 909b43fe3a
commit b7bfb17bef
3 changed files with 32 additions and 0 deletions

View File

@@ -2070,6 +2070,17 @@ If `callback` is provided, it is not invoked until all active sessions have been
closed, although the server has already stopped allowing new sessions. See
[`net.Server.close()`][] for more details.
#### `server[Symbol.asyncDispose]()`
<!-- YAML
added: REPLACEME
-->
> Stability: 1 - Experimental
Calls [`server.close()`][] and returns a promise that fulfills when the
server has closed.
#### `server.setTimeout([msecs][, callback])`
<!-- YAML
@@ -4226,6 +4237,7 @@ you need to implement any fall-back behavior yourself.
[`response.write(data, encoding)`]: http.md#responsewritechunk-encoding-callback
[`response.writeContinue()`]: #responsewritecontinue
[`response.writeHead()`]: #responsewriteheadstatuscode-statusmessage-headers
[`server.close()`]: #serverclosecallback
[`server.maxHeadersCount`]: http.md#servermaxheaderscount
[`tls.Server.close()`]: tls.md#serverclosecallback
[`tls.TLSSocket`]: tls.md#class-tlstlssocket

View File

@@ -26,6 +26,7 @@ const {
SafeSet,
StringPrototypeSlice,
Symbol,
SymbolAsyncDispose,
TypedArrayPrototypeGetLength,
Uint32Array,
Uint8Array,
@@ -3189,6 +3190,10 @@ class Http2Server extends NETServer {
validateSettings(settings);
this[kOptions].settings = { ...this[kOptions].settings, ...settings };
}
async [SymbolAsyncDispose]() {
return FunctionPrototypeCall(promisify(super.close), this);
}
}
Http2Server.prototype[EventEmitter.captureRejectionSymbol] = function(

View File

@@ -0,0 +1,15 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const server = http2.createServer();
server.listen(0, common.mustCall(() => {
server.on('close', common.mustCall());
server[Symbol.asyncDispose]().then(common.mustCall());
}));