https: 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:29:58 +03:00 committed by Moshe Atlow
parent b7bfb17bef
commit e8810b91f1
No known key found for this signature in database
GPG Key ID: CB1159A696865149
3 changed files with 37 additions and 0 deletions

View File

@ -135,6 +135,17 @@ added: v0.1.90
See [`server.close()`][] in the `node:http` module.
### `server[Symbol.asyncDispose]()`
<!-- YAML
added: REPLACEME
-->
> Stability: 1 - Experimental
Calls [`server.close()`][httpsServerClose] and returns a promise that
fulfills when the server has closed.
### `server.closeAllConnections()`
<!-- YAML
@ -571,4 +582,5 @@ headers: max-age=0; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; p
[`tls.connect()`]: tls.md#tlsconnectoptions-callback
[`tls.createSecureContext()`]: tls.md#tlscreatesecurecontextoptions
[`tls.createServer()`]: tls.md#tlscreateserveroptions-secureconnectionlistener
[httpsServerClose]: #serverclosecallback
[sni wiki]: https://en.wikipedia.org/wiki/Server_Name_Indication

View File

@ -33,11 +33,13 @@ const {
ObjectSetPrototypeOf,
ReflectApply,
ReflectConstruct,
SymbolAsyncDispose,
} = primordials;
const {
assertCrypto,
kEmptyObject,
promisify,
} = require('internal/util');
assertCrypto();
@ -110,6 +112,10 @@ Server.prototype.close = function() {
ReflectApply(tls.Server.prototype.close, this, arguments);
};
Server.prototype[SymbolAsyncDispose] = async function() {
return FunctionPrototypeCall(promisify(this.close), this);
};
/**
* Creates a new `https.Server` instance.
* @param {{

View File

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