GeezerVison is showing github.com — http: server add async dispose · nodejs/node@94ebb02
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -1667,6 +1667,17 @@ to 8.0.0, which did not have a keep-alive timeout. | 1667 | 1667 | The socket timeout logic is set up on connection, so changing this value only | 1668 | 1668 | affects new connections to the server, not any existing connections. | 1669 | 1669 |
| | 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 | + | 1670 | 1681 | ## Class: `http.ServerResponse` | 1671 | 1682 |
| 1672 | 1683 | <!-- YAML | @@ -3895,6 +3906,7 @@ Set the maximum number of idle HTTP parsers. | 3895 | 3906 | [`response.write(data, encoding)`]: #responsewritechunk-encoding-callback | 3896 | 3907 | [`response.writeContinue()`]: #responsewritecontinue | 3897 | 3908 | [`response.writeHead()`]: #responsewriteheadstatuscode-statusmessage-headers | | 3909 | +[`server.close()`]: #serverclosecallback | 3898 | 3910 | [`server.headersTimeout`]: #serverheaderstimeout | 3899 | 3911 | [`server.keepAliveTimeout`]: #serverkeepalivetimeout | 3900 | 3912 | [`server.listen()`]: net.md#serverlisten | |
Collapse file Copy file name to clipboardExpand all lines: lib/_http_server.js +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 24 | 24 | const { | 25 | 25 | ArrayIsArray, | 26 | 26 | Error, | | 27 | + FunctionPrototypeCall, | 27 | 28 | MathMin, | 28 | 29 | ObjectKeys, | 29 | 30 | ObjectSetPrototypeOf, | 30 | 31 | RegExpPrototypeExec, | 31 | 32 | ReflectApply, | 32 | 33 | Symbol, | | 34 | + SymbolAsyncDispose, | 33 | 35 | SymbolFor, | 34 | 36 | } = primordials; | 35 | 37 |
| @@ -81,6 +83,7 @@ const { | 81 | 83 | } = codes; | 82 | 84 | const { | 83 | 85 | kEmptyObject, | | 86 | + promisify, | 84 | 87 | } = require('internal/util'); | 85 | 88 | const { | 86 | 89 | validateInteger, | @@ -557,6 +560,10 @@ Server.prototype.close = function() { | 557 | 560 | ReflectApply(net.Server.prototype.close, this, arguments); | 558 | 561 | }; | 559 | 562 |
| | 563 | +Server.prototype[SymbolAsyncDispose] = async function() { | | 564 | + return FunctionPrototypeCall(promisify(this.close), this); | | 565 | +}; | | 566 | + | 560 | 567 | Server.prototype.closeAllConnections = function() { | 561 | 568 | const connections = this[kConnections].all(); | 562 | 569 |
| |
Collapse file Copy file name to clipboard +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +})); |
|