Skip to content

Commit 3927630

Browse files
committed
throw error if attempting to close server when not listening
1 parent eba07f1 commit 3927630

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/Server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class Server extends EventEmitter<Server.Events> {
6363
* @param [timeout=5000] Maximum time to wait for existing connections to close before forcibly closing them.
6464
*/
6565
public async close(timeout = 5000): Promise<void> {
66+
if (!this.server.listening)
67+
throw new Error("Server is not listening.");
6668
this.emit("closing");
6769
let timeoutId: NodeJS.Timeout;
6870
await Promise.race([

0 commit comments

Comments
 (0)