Blocking Call In Async (ARCH3028)
Ce contenu n’est pas encore disponible dans votre langue.
Key typescript.async.blocking-call-in-async · Severity error · Category async
Synchronous blocking calls (sleep, blocking IO, blocking HTTP/DB drivers) inside an async function stall the event loop and starve concurrency.
Incorrect
Section titled “Incorrect”import { readFileSync } from "fs";
async function loadTemplate(path: string): Promise<string> { return readFileSync(path, "utf8"); // blocks the event loop}Correct
Section titled “Correct”import { readFile } from "fs/promises";
async function loadTemplate(path: string): Promise<string> { return await readFile(path, "utf8");}Replace the synchronous blocking call with its asynchronous, awaitable counterpart.