Skip to content

Commit bd52b5a

Browse files
committed
http2: Server add asyncDispose
1 parent 81f630f commit bd52b5a

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

doc/api/http2.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,18 @@ 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+
2074+
#### `server[Symbol.asyncDispose]()`
2075+
2076+
<!-- YAML
2077+
added: REPLACEME
2078+
-->
2079+
2080+
> Stability: 1 - Experimental
2081+
2082+
Calls [`server.close()`][] and returns a promise that fulfills when the
2083+
server has closed.
2084+
20732085
#### `server.setTimeout([msecs][, callback])`
20742086

20752087
<!-- YAML
@@ -4226,6 +4238,7 @@ you need to implement any fall-back behavior yourself.
42264238
[`response.write(data, encoding)`]: http.md#responsewritechunk-encoding-callback
42274239
[`response.writeContinue()`]: #responsewritecontinue
42284240
[`response.writeHead()`]: #responsewriteheadstatuscode-statusmessage-headers
4241+
[`server.close()`]: #serverclosecallback
42294242
[`server.maxHeadersCount`]: http.md#servermaxheaderscount
42304243
[`tls.Server.close()`]: tls.md#serverclosecallback
42314244
[`tls.TLSSocket`]: tls.md#class-tlstlssocket

lib/internal/http2/core.js

Lines changed: 5 additions & 0 deletions
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 promisify(super.close).call(this);
3196+
}
31923197
}
31933198

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

0 commit comments

Comments
 (0)