aboutsummaryrefslogtreecommitdiff
path: root/examples/http-stop.ts
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-11 04:58:29 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-11 04:58:29 -0700
commit3e969244ac2a1b60ba7cea2aeff286b0d5dc3dc6 (patch)
tree923d54a2bf187b1827865ad26c59fadd6b5f019d /examples/http-stop.ts
parentac3835227eb66ea340122db614e6f32fa17a5697 (diff)
downloadbun-3e969244ac2a1b60ba7cea2aeff286b0d5dc3dc6.tar.gz
bun-3e969244ac2a1b60ba7cea2aeff286b0d5dc3dc6.tar.zst
bun-3e969244ac2a1b60ba7cea2aeff286b0d5dc3dc6.zip
[bun.js] Add a `Server.stop` function
Diffstat (limited to 'examples/http-stop.ts')
-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);