mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
[node:http] Fix close() to accept a callback and implement closeAllConnections
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user