aboutsummaryrefslogtreecommitdiff
path: root/examples/http-stop.ts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--examples/http-stop.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/examples/http-stop.ts b/examples/http-stop.ts
new file mode 100644
index 000000000..64d3abfa1
--- /dev/null
+++ b/examples/http-stop.ts
@@ -0,0 +1,12 @@
+const server = Bun.serve({
+ fetch(req: Request) {
+ return new Response(`Pending requests: ${this?.pendingRequests ?? 0}`);
+ },
+});
+
+setTimeout(() => {
+ // stop the server after the first request
+ // when the server is stopped, this becomes undefined
+ server?.stop();
+ console.log("Stopping the server...");
+}, 1000);