diff options
author | 2023-05-11 15:09:14 -0700 | |
---|---|---|
committer | 2023-05-11 15:09:14 -0700 | |
commit | d67bdb7e9baf397d58eee458b9de7fee90d16bb7 (patch) | |
tree | 3174a58e72f28181a727d4797ad615077e8f5f4c | |
parent | 77eb61a1fe8c1bf7ad21958fa95be7a9acc005b8 (diff) | |
download | bun-d67bdb7e9baf397d58eee458b9de7fee90d16bb7.tar.gz bun-d67bdb7e9baf397d58eee458b9de7fee90d16bb7.tar.zst bun-d67bdb7e9baf397d58eee458b9de7fee90d16bb7.zip |
[node:http] Fix `close()` to accept a callback and implement `closeAllConnections`
-rw-r--r-- | src/bun.js/http.exports.js | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/bun.js/http.exports.js b/src/bun.js/http.exports.js index dda9664bb..0e0686961 100644 --- a/src/bun.js/http.exports.js +++ b/src/bun.js/http.exports.js @@ -221,12 +221,30 @@ export class Server extends EventEmitter { if (callback) this.on("request", callback); } - close() { - if (this.#server) { - this.emit("close"); - this.#server.stop(); - this.#server = undefined; + closeAllConnections() { + const server = this.#server; + if (!server) { + return; + } + this.#server = undefined; + server.stop(true); + this.emit("close"); + } + + closeIdleConnections() { + // not actually implemented + } + + close(optionalCallback) { + const server = this.#server; + if (!server) { + if (typeof optionalCallback === "function") process.nextTick(new Error("Server is not running")); + return; } + this.#server = undefined; + if (typeof optionalCallback === "function") this.once("close", optionalCallback); + this.emit("close"); + server.stop(); } address() { |