Skip to content

Commit 8c3893b

Browse files
committed
add timeout param to Server#close()
1 parent cb71427 commit 8c3893b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Server.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ class Server extends EventEmitter<Server.Events> {
5858
return this.server.keepAliveTimeout;
5959
}
6060

61-
public async close(): Promise<void> {
61+
/**
62+
* Close the server. Will stop accepting new connections and wait for existing connections to close.
63+
* @param [timeout=5000] Maximum time to wait for existing connections to close before forcibly closing them.
64+
*/
65+
public async close(timeout = 5000): Promise<void> {
6266
this.emit("closing");
6367
await Promise.race([
6468
new Promise<void>(resolve => {
@@ -67,7 +71,7 @@ class Server extends EventEmitter<Server.Events> {
6771
new Promise<void>(resolve => setTimeout(() => {
6872
this.server.closeAllConnections();
6973
resolve();
70-
}, 5000)),
74+
}, timeout)),
7175
]);
7276
this.emit("closed");
7377
}

0 commit comments

Comments
 (0)