GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http: server add async dispose · nodejs/node@94ebb02

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • http.md
  • lib
    • _http_server.js
  • test/parallel
    • test-http-server-async-dispose.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/http.md‎

Copy file name to clipboardExpand all lines: doc/api/http.md
+12Lines changed: 12 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,17 @@ to 8.0.0, which did not have a keep-alive timeout.
16671667
The socket timeout logic is set up on connection, so changing this value only
16681668
affects new connections to the server, not any existing connections.
16691669

1670+
### `server[Symbol.asyncDispose]()`
1671+
1672+
<!-- YAML
1673+
added: REPLACEME
1674+
-->
1675+
1676+
> Stability: 1 - Experimental
1677+
1678+
Calls [`server.close()`][] and returns a promise that fulfills when the
1679+
server has closed.
1680+
16701681
## Class: `http.ServerResponse`
16711682

16721683
<!-- YAML
@@ -3895,6 +3906,7 @@ Set the maximum number of idle HTTP parsers.
38953906
[`response.write(data, encoding)`]: #responsewritechunk-encoding-callback
38963907
[`response.writeContinue()`]: #responsewritecontinue
38973908
[`response.writeHead()`]: #responsewriteheadstatuscode-statusmessage-headers
3909+
[`server.close()`]: #serverclosecallback
38983910
[`server.headersTimeout`]: #serverheaderstimeout
38993911
[`server.keepAliveTimeout`]: #serverkeepalivetimeout
39003912
[`server.listen()`]: net.md#serverlisten
Collapse file

‎lib/_http_server.js‎

Copy file name to clipboardExpand all lines: lib/_http_server.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
const {
2525
ArrayIsArray,
2626
Error,
27+
FunctionPrototypeCall,
2728
MathMin,
2829
ObjectKeys,
2930
ObjectSetPrototypeOf,
3031
RegExpPrototypeExec,
3132
ReflectApply,
3233
Symbol,
34+
SymbolAsyncDispose,
3335
SymbolFor,
3436
} = primordials;
3537

@@ -81,6 +83,7 @@ const {
8183
} = codes;
8284
const {
8385
kEmptyObject,
86+
promisify,
8487
} = require('internal/util');
8588
const {
8689
validateInteger,
@@ -557,6 +560,10 @@ Server.prototype.close = function() {
557560
ReflectApply(net.Server.prototype.close, this, arguments);
558561
};
559562

563+
Server.prototype[SymbolAsyncDispose] = async function() {
564+
return FunctionPrototypeCall(promisify(this.close), this);
565+
};
566+
560567
Server.prototype.closeAllConnections = function() {
561568
const connections = this[kConnections].all();
562569

Collapse file

‎test/parallel/test-http-server-async-dispose.js‎

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const { createServer } = require('http');
5+
const { kConnectionsCheckingInterval } = require('_http_server');
6+
7+
const server = createServer();
8+
9+
server.listen(0, common.mustCall(() => {
10+
server.on('close', common.mustCall());
11+
server[Symbol.asyncDispose]().then(common.mustCall(() => {
12+
assert(server[kConnectionsCheckingInterval]._destroyed);
13+
}));
14+
}));

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.