deploy_feedback
deploy_feedback copied to clipboard
Missing Deno.readTextFileSync
Hey! How's everyone going? I hope everyone's doing well.
I tried using Deno.readTextFileSync and I realized it is still unsuported. Of couse one can make it work by replacing it with this:
const file = Deno.readTextFileSync('./path').trim(); // Best method
const file_2 = ( await Deno.readTextFile('./path') ).trim(); // A way around it
It works, but can become a bit messy. Are there any plans to implement this and other missing Deno APIs? These can get a bit messy if we need to perform them under "non async" functions. Thanks!!
No, we are not planning to introduce the sync APIs. Sync APIs block all execution, which can cause other requests to hang. If you are reading a large file with a sync
API for example, setTimeout
will not fire while that file is being loaded.
You should always use asynchronous APIs.
No, we are not planning to introduce the sync APIs. Sync APIs block all execution, which can cause other requests to hang. If you are reading a large file with a
sync
API for example,setTimeout
will not fire while that file is being loaded.You should always use asynchronous APIs.
In my case, I use some server-side rendering which currently reads some pretty small files only once during setup, which I might optimize later, but the behavior I need is a sync one, which would be non-blocking anyway due to it being performed once before any requests are processed. And one can always do ( await Deno.readTextFile('./path') )
anyway
I cant see how there is ever a technical reason for using sync instead of async.
I my mind you just put an "await" in front of the sync one and you have the same behaviour. There must be something I dont understand about your setup @pedropaulosuzuki
I cant see how there is ever a technical reason for using sync instead of async.
I my mind you just put an "await" in front of the sync one and you have the same behaviour. There must be something I dont understand about your setup @pedropaulosuzuki
Well, you cannot use await outside of async functions unless you're at the global scope. And when you start chaining methods, it only works with the ugly parenthesis around it.
function foo() {
// Won't work inside this function unless it is async
const data = ( await Deno.readTextFile('./path.csv') ).trim().split('\n')
.map(row => row.trim().split(';').map(cell => cell.trim()));
// This would
const data = Deno.readTextFileSync('./path.csv').trim().split('\n')
.map(row => row.trim().split(';').map(cell => cell.trim()));
}
Deno.readTextFileSync
is now supported on Deno Deploy.