aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/http-stop.ts10
-rw-r--r--types/bun/bun.d.ts2
2 files changed, 6 insertions, 6 deletions
diff --git a/examples/http-stop.ts b/examples/http-stop.ts
index 64d3abfa1..f31dac616 100644
--- a/examples/http-stop.ts
+++ b/examples/http-stop.ts
@@ -1,12 +1,10 @@
const server = Bun.serve({
fetch(req: Request) {
- return new Response(`Pending requests: ${this?.pendingRequests ?? 0}`);
+ return new Response(`Pending requests: ${this.pendingRequests}`);
},
});
+// Stop the server after 5 seconds
setTimeout(() => {
- // stop the server after the first request
- // when the server is stopped, this becomes undefined
- server?.stop();
- console.log("Stopping the server...");
-}, 1000);
+ server.stop();
+}, 5000);
diff --git a/types/bun/bun.d.ts b/types/bun/bun.d.ts
index c9f3ebb5b..b20508529 100644
--- a/types/bun/bun.d.ts
+++ b/types/bun/bun.d.ts
@@ -567,6 +567,8 @@ declare module "bun" {
* Stop listening to prevent new connections from being accepted.
*
* It does not close existing connections.
+ *
+ * It may take a second or two to actually stop.
*/
stop(): void;