mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
15
test/parallel/test-http2-server-async-dispose.js
Normal file
15
test/parallel/test-http2-server-async-dispose.js
Normal 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());
|
||||
}));
|
||||
Reference in New Issue
Block a user