#Preventing `Deno.stdin` reads from blocking

12 messages · Page 1 of 1 (latest)

hot parrot
#

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");
  /* ... */
}
hot parrot
tawdry oak
#

Which version of Deno do you use?

hot parrot
#

latest

#

Preventing Deno.stdin reads from blocking

#

its really infuriating because it prevents me from restarting the app in case something breaks

tawdry oak
#

That is really annoying. Hop some of the core team members read this

lofty panther
hot parrot
#

good to know it is in fact a bug

#

(and that it gained some attention, which i appreciate a lot)

lofty panther
#

Stalebot used to be a bit of a pain 🙂 Hence why it was removed.