mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
http: server add async dispose
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
893c000046
commit
909b43fe3a
@ -1667,6 +1667,17 @@ to 8.0.0, which did not have a keep-alive timeout.
|
||||
The socket timeout logic is set up on connection, so changing this value only
|
||||
affects new connections to the server, not any existing connections.
|
||||
|
||||
### `server[Symbol.asyncDispose]()`
|
||||
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
> Stability: 1 - Experimental
|
||||
|
||||
Calls [`server.close()`][] and returns a promise that fulfills when the
|
||||
server has closed.
|
||||
|
||||
## Class: `http.ServerResponse`
|
||||
|
||||
<!-- YAML
|
||||
@ -3895,6 +3906,7 @@ Set the maximum number of idle HTTP parsers.
|
||||
[`response.write(data, encoding)`]: #responsewritechunk-encoding-callback
|
||||
[`response.writeContinue()`]: #responsewritecontinue
|
||||
[`response.writeHead()`]: #responsewriteheadstatuscode-statusmessage-headers
|
||||
[`server.close()`]: #serverclosecallback
|
||||
[`server.headersTimeout`]: #serverheaderstimeout
|
||||
[`server.keepAliveTimeout`]: #serverkeepalivetimeout
|
||||
[`server.listen()`]: net.md#serverlisten
|
||||
|
@ -24,12 +24,14 @@
|
||||
const {
|
||||
ArrayIsArray,
|
||||
Error,
|
||||
FunctionPrototypeCall,
|
||||
MathMin,
|
||||
ObjectKeys,
|
||||
ObjectSetPrototypeOf,
|
||||
RegExpPrototypeExec,
|
||||
ReflectApply,
|
||||
Symbol,
|
||||
SymbolAsyncDispose,
|
||||
SymbolFor,
|
||||
} = primordials;
|
||||
|
||||
@ -81,6 +83,7 @@ const {
|
||||
} = codes;
|
||||
const {
|
||||
kEmptyObject,
|
||||
promisify,
|
||||
} = require('internal/util');
|
||||
const {
|
||||
validateInteger,
|
||||
@ -557,6 +560,10 @@ Server.prototype.close = function() {
|
||||
ReflectApply(net.Server.prototype.close, this, arguments);
|
||||
};
|
||||
|
||||
Server.prototype[SymbolAsyncDispose] = async function() {
|
||||
return FunctionPrototypeCall(promisify(this.close), this);
|
||||
};
|
||||
|
||||
Server.prototype.closeAllConnections = function() {
|
||||
const connections = this[kConnections].all();
|
||||
|
||||
|
14
test/parallel/test-http-server-async-dispose.js
Normal file
14
test/parallel/test-http-server-async-dispose.js
Normal file
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const { createServer } = require('http');
|
||||
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