Mqx
Mqx17mo ago

Deno stopps at file.read()

I am currently working on a way to communicate with a COM device. I can successfully open and read from the COM port. The only problem is, is there is no data on the COM port Deno pauses at that point in the code because the Promise gets neither resolved or rejected. Here is the link to the Stackoverflow problem. https://stackoverflow.com/questions/75400521/abort-promise-after-delay-in-deno
Stack Overflow
Abort Promise after delay in Deno
I am currently trying to open a COM port with Deno. This works so far and I can read the data with file.read(buffer). The only problem now is that if there is no more data in the COM port and I try...
16 Replies
Mqx
Mqx17mo ago
Hope someone can help 👍🏻
AapoAlas
AapoAlas17mo ago
setTimeout and call close on your COM instance to close the read.
Mqx
Mqx17mo ago
I tried that and it does not work…
AapoAlas
AapoAlas17mo ago
You can also do a await Promise.race([file.read(), new Promise(res => setTimeout(res, TIMEOUT_MS))]) in the read method to internally include a timeout. I can't remember if the read API supports it but if it does then AbortSignal is a "native" way to cancel an ongoing promise.
Mqx
Mqx17mo ago
Yes ChatGPT also suggested that 😅 only problem is that the program does not close because there are this one pending promise The AbortSignal only works on readTextFile() method file.read(buffer) has no abortSignal
AapoAlas
AapoAlas17mo ago
Hmm, does it not close even if you call the close() on it afterwards? I guess the readable stream API might offer what you need, though I don't know how much you need the "read n chars" API you have for COM right now. Note though that file.read(buffer) does not guarantee that the buffer is "filled". It returns the number of bytes actually read.
Mqx
Mqx17mo ago
A readable stream does not work because the COM ports are some how different
AapoAlas
AapoAlas17mo ago
There is also some internal API at least for unref'ing a Promise, ie. telling Deno that you do not care about a given Promise resolving or not anymore...
Mqx
Mqx17mo ago
Okay
AapoAlas
AapoAlas17mo ago
Possibly Deno[Deno.internal].unrefPromise
Mqx
Mqx17mo ago
I hope that they add a serial API in the future… Okay
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Mqx
Mqx17mo ago
Nope 😅 I have written with djDev (creator of deno_seial) library and he fixed some parts. But set main branch still does not work. The library he created is awesome, but you need to use a sub branch that is not listed. The branch is als unstable. https://raw.githubusercontent.com/DjDeveloperr/deno_serial/bddff5b/mod.ts I am just @ˋMqxxˋ on GitHub
AapoAlas
AapoAlas17mo ago
What sort of fixes did you make?
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Mqx
Mqx17mo ago
I did no fixes