diff options
author | 2022-04-11 04:58:29 -0700 | |
---|---|---|
committer | 2022-04-11 04:58:29 -0700 | |
commit | 3e969244ac2a1b60ba7cea2aeff286b0d5dc3dc6 (patch) | |
tree | 923d54a2bf187b1827865ad26c59fadd6b5f019d /examples | |
parent | ac3835227eb66ea340122db614e6f32fa17a5697 (diff) | |
download | bun-3e969244ac2a1b60ba7cea2aeff286b0d5dc3dc6.tar.gz bun-3e969244ac2a1b60ba7cea2aeff286b0d5dc3dc6.tar.zst bun-3e969244ac2a1b60ba7cea2aeff286b0d5dc3dc6.zip |
[bun.js] Add a `Server.stop` function
Diffstat (limited to 'examples')
-rw-r--r-- | examples/http-stop.ts | 12 | ||||
-rw-r--r-- | examples/http.ts | 1 |
2 files changed, 12 insertions, 1 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); diff --git a/examples/http.ts b/examples/http.ts index 97caf6bfc..8b17c320c 100644 --- a/examples/http.ts +++ b/examples/http.ts @@ -21,7 +21,6 @@ Bun.serve({ port: 3000, // number or string }); - // Start a fast HTTP server from the main file's export // export default { // fetch(req) { |