denoland / deno_lint

Blazing fast linter for JavaScript and TypeScript written in Rust
https://lint.deno.land/
MIT License
1.53k stars 172 forks source link

warn about sync usage inside async function #1177

Closed sigmaSd closed 1 year ago

sigmaSd commented 1 year ago

I think it would be nice to have a lint that warns like this

async function doStuff() {
   Deno.readTextFileSync("") // warning here: using a sync function inside an async function, this blocks deno event loop, you should consider changing it to an async function 
  }

Don't know how this stuff is implemented, but I imagine that sync function blocks tokio executor, so no other async function will proceed, here is an example program that showcases my assumption

setInterval(() => console.log(4), 1000);
//Deno.readTextFileSync("/dev/random"); // if this is uncommented, no logging will be printed
//await Deno.readTextFile("/dev/random"); // if this is uncommneted, logging will still work