Ir al contenido

Sync Over Async (ARCH3023)

Esta página aún no está disponible en tu idioma.

Key typescript.async.sync-over-async · Severity error · Category async

Blocking on an asynchronous operation from a synchronous context risks deadlock, starves the thread pool, and defeats the entire purpose of async.

import { execSync } from "child_process";
function readConfig(): string {
// synchronous call blocks the event loop
return execSync("cat config.json").toString();
}
import { readFile } from "fs/promises";
async function readConfig(): Promise<string> {
return await readFile("config.json", "utf8");
}

Use the asynchronous counterpart of the blocking API and await the call instead of blocking.