D
Deno

help

Preventing `Deno.stdin` reads from blocking

Wwulfey4/22/2023
In a module for reading Deno.stdin input, there is a loop that reads and parses the returned bytes. My issue is that, in case of an uncaught error/rejection, the process hangs until stdin has something to return, and once it does, only then does it exit the process and log the error information. Is there a way to make this read() non-blocking in that sense? If the user does not input anything, but an error occurs, the process should exit immediately and not have to wait for a keypress. The code below can be run from a file for demonstration.
// Uncaught error timeout
setTimeout(() => { throw new Error(); }, 5000);

const input = Deno.stdin;
input.setRaw(true, Deno.build.os === "windows" ? undefined : { cbreak: true });
while (true) {
let bytes: Uint8Array = new Uint8Array(4096);
// If an uncaught error occurs somewhere else
// Deno waits for the read to complete before exiting.
await input.read(bytes);
console.log("read some bytes");
/* ... */
}
// Uncaught error timeout
setTimeout(() => { throw new Error(); }, 5000);

const input = Deno.stdin;
input.setRaw(true, Deno.build.os === "windows" ? undefined : { cbreak: true });
while (true) {
let bytes: Uint8Array = new Uint8Array(4096);
// If an uncaught error occurs somewhere else
// Deno waits for the read to complete before exiting.
await input.read(bytes);
console.log("read some bytes");
/* ... */
}
(actually, there is an issue about this at https://github.com/denoland/deno/issues/14333, but it hasn't gotten any attention for about 8 months)
MMrKleeblatt4/22/2023
Which version of Deno do you use?
Wwulfey4/22/2023
latest its really infuriating because it prevents me from restarting the app in case something breaks
MMrKleeblatt4/23/2023
That is really annoying. Hop some of the core team members read this
AAapoAlas4/27/2023
This is likely related to / same issue as https://github.com/denoland/deno/issues/18131
GitHub
FFI: Errors cannot be thrown after a nonblocking function call ยท ...
call_some_nonblocking_function(); console.debug("Reaches here."); throw new Error(); // not thrown
Wwulfey4/29/2023
heh
Wwulfey4/29/2023
good to know it is in fact a bug (and that it gained some attention, which i appreciate a lot)
AAapoAlas4/29/2023
Stalebot used to be a bit of a pain ๐Ÿ™‚ Hence why it was removed. Whether or not this is a bug or a feature could perhaps be debated. I would personally opt on the side of "it's a bug" but I'm sure someone could argue the opposite as well. I'll try my best to get some attention to this but don't expect too much. It's a painful edge case with only annoying answers on offer (I believe).

Looking for more? Join the community!

Recommended Posts
Can I pre-cache dependencies that I specify using npm:?Hi! Trying to figure out the right way to combine Deno's module support to make our deploys consisteJSON Schema Core, $dynamicAnchor, and $vocabularySlightly off-topic, but I'm writing a Deno library. Anyone deeply knowledgeable on JSON Schema CoreTest case is leaking resourcesHi, all my tests keeps failing because of ```json error: AssertionError: Test case is leaking 2 reso[have workaround] "deno" and "deno repl" aren't producing outputI typed in "deno" and nothing happened, and I thought it was finally doing the right thing when no aServe Fresh over HTTPS locallyHow can I serve Fresh over HTTPS locally? In node I might generate certs and do ``` https.createSercli/tsc crashes with Uncaught TypeErrorUsing latest Deno (1.32.4), this only happens on certain files, but it effectively means that I cannFresh: <Head> component is not supportedWhen running `deno task start` with this as my `pages/index.tsx` file (as in the demo) I'm seeing tIs there a way to vendor npm specifier imports?> deno vendor npm:express > Vendored 0 modules into scripts/vendor directoryHow can I import with npm: specifiers through a proxy?My company blocks npmjs.com and they have setup an internal Artifactory instance. With nodejs I can Import modules from all files in directoryConsidering I have multiple ts files in a folder and all of them export the same type module. Can I Parsing Apache mime.types into dictionary Record<string, string>This code parses the official Apache `mime.types` from GitHub and creates a dictionary `Record<strinProvide own default error page in FreshHello! I'm seeing the following error ```pragma cannot be set when runtime is automatic at https:/Smoother DX using 3rd party modules written in TypeScript in the BrowserSay, for instance, I want to use the "async" standard library's Deferred implementation in some codegrpc / http2 / https in fresh.please a correct way to use grpc / http2 / https in fresh.Importing local Node.js modulesI have a local Node.js/TS package in local directory `/foo/bar/leet/package.json` โ€“ Is there any wayServer Sent Events with FreshHi! I am trying to use Server Sent Events (SSE) with fresh. I understand I should have an island thaTwind intellisense stop workingOut of the blue, intellisense stopped working even though I installed the twind and deno extensions How use namespace on Denoi am trying to use the same namespace in multiple modules but what used to work in node, doesn't worRestart Deno process on crashHello, The following Node snippet allows a script to restart on crash : ```js import { spawn } fbest practice when spawning commands that require sudo?I am building a command line utility in deno that leverages data coming from `tcpdump`. To get any m