diff options
author | 2022-04-11 05:20:44 -0700 | |
---|---|---|
committer | 2022-04-11 05:20:44 -0700 | |
commit | 55ff561429565509d2c92071f5561c81599ae37b (patch) | |
tree | 423924a60e26cd49cee40de5af17f5b976e063bf | |
parent | 4708dd26cac2a3c0f5fac740252cbe5b51e77a79 (diff) | |
download | bun-55ff561429565509d2c92071f5561c81599ae37b.tar.gz bun-55ff561429565509d2c92071f5561c81599ae37b.tar.zst bun-55ff561429565509d2c92071f5561c81599ae37b.zip |
Add example for stopping HTTP server
Diffstat (limited to '')
-rw-r--r-- | examples/http-stop.ts | 10 | ||||
-rw-r--r-- | types/bun/bun.d.ts | 2 |
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; |