mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00:00
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:
parent
b7bfb17bef
commit
e8810b91f1
@ -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
|
||||
|
||||
@ -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 {{
|
||||
|
||||
19
test/parallel/test-https-server-async-dispose.js
Normal file
19
test/parallel/test-https-server-async-dispose.js
Normal 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);
|
||||
}));
|
||||
}));
|
||||
Loading…
Reference in New Issue
Block a user