D
Deno

help

Close a Deno.serve() connection?

Sshawnbu8/17/2023
Is it possible to close a Deno.serve() connection?
IioB8/17/2023
Do you mean the server or the connection? If you mean the server, you should use the web-standard AbortSignal API:
const controller = new AbortController();
const signal = controller.signal;

Deno.serve({ signal }, () => {
// whenever you want to close the server
controller.abort();
})
const controller = new AbortController();
const signal = controller.signal;

Deno.serve({ signal }, () => {
// whenever you want to close the server
controller.abort();
})
Sshawnbu8/17/2023
Oh wow! I thought I found it through unref(), this seems nicer. How would I close the connection outside the request loop?
IioB8/17/2023
You could close the connection outside of the request loop like you'd expect! Just call controller.abort();
Sshawnbu8/17/2023
If I have many Deno.servers going on for different ports (which is what I'm doing), how do I map a controller to a specific server? Oh, I pass the signal instance into the server? I see. And then how to pass configs with the signal at the same time? Forgive me, I'm new to Deno and trying to figure it all how.
IioB8/17/2023
Presumably you'd want to shut down the servers at different times? If that's the case, I think you got it. If that's not the case, you only need one abort controller!
Sshawnbu8/17/2023
Thanks so much for helping me with your answers.
Yes, at different times. I can remote send a command to do it. only thing is how to initialize server with the signal and config props at the same time (for port)
Llcasdev8/17/2023
Next to the signal, you can specify a port property

Looking for more? Join the community!

Recommended Posts
Relative import path "preact" not prefixed with / or ./ or ../ at https://deno.land/x/fresh@1.4.Please help. ``` deno 1.36.1 (release, aarch64-apple-darwin) v8 11.6.189.12 typescript 5.1.6 ```Problems with Deno KV```ts import InputLoop from "https://deno.land/x/input@2.0.3/index.ts"; const kv = await Deno.openKFile differs only by case errorI'm getting a strange error from TypeScript. For some reason it thinks the case of my file name is Possible to have multiple http servers listening to different ports in the same module?I'm porting a service mesh platform we wrote for NodeJS over to Deno and it is based on the idea of How to have private state in embedded deno_core JsRuntime?I need to either keep a reference in rust to an object I then `delete globalThis.__context`, but I cIssues getting local environment running in VSCode and Visual Studio 2022I'm a windows user trying to contribute on an github issue, but I've run into a few blockers. Using Relative import path "ioredis" not prefixed with / or ./ or ../```ts // main.ts import Redis from "ioredis"; ``` ```json // deno.json { "imports": { "ioredisPixi.js breaks DenoI'm trying to import Pixi in a Fresh island: ``` import { Sprite, Stage } from "npm:@pixi/react@7.1Confused by deno vendor-related behaviorsI created a main.ts containing this code: ``` import * as thrift from "npm:thrift"; let connection =How to release node:zlib resourcesI have some testcases which use the `node:zlib` polyfill and I'm having a bit of trouble getting theDeno Repl ProgrammaticallyPython has a really nice not-well-known tool for creating a repl at any point in the code (kinda likDeno for SASS dependencies?I'm trying to understand how I would migrate from Jekyll and NPM to Lume and Deno. Specifically, I uHow can I send a number across a Deno.TcpConn as stream of bytes?I need to send a number across a Deno.TcpConn as 4 bytes, so it can be read by a server as an int32.Migrating `Deno.run` to `Deno.command` with `readlines`I had the following: ```ts browserProcess = Deno.run({ cmd: buildArgs, // eg chrome exe path, thError: Not implemented: crypto.KeyObject.prototype.asymmetricKeyTypeHello. Im trying to create a RSA Keypair, using the node **crypto.generateKeyPair** function, but i `Uncaught TypeError: encode is not a function` when using npm module `@kubernetes-client/node`I'm trying to use a particular call in the npm module `@kubernetes/client-node` from deno, but I'm gLinking to external codeif i want to link to external code, do i have to import it from https://deno.land?Impossible to install Deno on Linux Ubuntu LTS (22.04) x86_64Hello Context & Tech : Trying to install Deno on Linux Ubuntu LTS v22.04 on x86_64 architecture PrGet length of video (stream. m3u8)In deno/typescript, how can i get the length of a specific video stream (m3u8)?github account blocked errori changed email my old account to another account and when i login to deno deploy with that account