Skip to content

Commit

Permalink
https: server add asyncDispose
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
atlowChemi authored and MoLow committed Jun 29, 2023
1 parent b7bfb17 commit e8810b9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doc/api/https.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ const {
ObjectSetPrototypeOf,
ReflectApply,
ReflectConstruct,
SymbolAsyncDispose,
} = primordials;

const {
assertCrypto,
kEmptyObject,
promisify,
} = require('internal/util');
assertCrypto();

Expand Down Expand Up @@ -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 {{
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-https-server-async-dispose.js
Original file line number Diff line number Diff line change
@@ -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);
}));
}));

0 comments on commit e8810b9

Please sign in to comment.