Skip to content

Commit 1aad923

Browse files
atlowChemiCeres6
authored andcommitted
http2: server add asyncDispose
PR-URL: nodejs#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>
1 parent 377a9f4 commit 1aad923

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

doc/api/http2.md

+12
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,17 @@ If `callback` is provided, it is not invoked until all active sessions have been
20702070
closed, although the server has already stopped allowing new sessions. See
20712071
[`net.Server.close()`][] for more details.
20722072

2073+
#### `server[Symbol.asyncDispose]()`
2074+
2075+
<!-- YAML
2076+
added: REPLACEME
2077+
-->
2078+
2079+
> Stability: 1 - Experimental
2080+
2081+
Calls [`server.close()`][] and returns a promise that fulfills when the
2082+
server has closed.
2083+
20732084
#### `server.setTimeout([msecs][, callback])`
20742085

20752086
<!-- YAML
@@ -4226,6 +4237,7 @@ you need to implement any fall-back behavior yourself.
42264237
[`response.write(data, encoding)`]: http.md#responsewritechunk-encoding-callback
42274238
[`response.writeContinue()`]: #responsewritecontinue
42284239
[`response.writeHead()`]: #responsewriteheadstatuscode-statusmessage-headers
4240+
[`server.close()`]: #serverclosecallback
42294241
[`server.maxHeadersCount`]: http.md#servermaxheaderscount
42304242
[`tls.Server.close()`]: tls.md#serverclosecallback
42314243
[`tls.TLSSocket`]: tls.md#class-tlstlssocket

lib/internal/http2/core.js

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const {
2626
SafeSet,
2727
StringPrototypeSlice,
2828
Symbol,
29+
SymbolAsyncDispose,
2930
TypedArrayPrototypeGetLength,
3031
Uint32Array,
3132
Uint8Array,
@@ -3189,6 +3190,10 @@ class Http2Server extends NETServer {
31893190
validateSettings(settings);
31903191
this[kOptions].settings = { ...this[kOptions].settings, ...settings };
31913192
}
3193+
3194+
async [SymbolAsyncDispose]() {
3195+
return FunctionPrototypeCall(promisify(super.close), this);
3196+
}
31923197
}
31933198

31943199
Http2Server.prototype[EventEmitter.captureRejectionSymbol] = function(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
8+
const http2 = require('http2');
9+
10+
const server = http2.createServer();
11+
12+
server.listen(0, common.mustCall(() => {
13+
server.on('close', common.mustCall());
14+
server[Symbol.asyncDispose]().then(common.mustCall());
15+
}));

0 commit comments

Comments
 (0)