Recent Posts
Archives

Posts Tagged ‘AsyncHooks’

PostHeaderIcon [NodeCongress2021] Don’t Try This at Home: Synchronous I/O in Node.js – Anna Henningsen

Node.js’s asynchronous creed—non-blocking I/O as ethos—clashes intriguingly with synchronous imperatives, where immediacy trumps concurrency. Anna Henningsen, erstwhile Node.js TSC member now at MongoDB’s dev tools cadre, probes this tension, cataloging detours from the async path and gleaning internals’ revelations. Pronouns she/her, Anna balances core contributions with family joys, her moniker addaleax echoing across Twitter and GitHub.

Anna queries the aversion: sync ops monopolize threads, stalling event loops—left pane’s stalled fetches versus right’s parallel prowess. Yet, exigencies persist: CLI bootstraps, config reads—fs.readFileSync reigns for startup simplicity.

Navigating Sync Detours and Their Perils

Anna enumerates evasions: worker_threads offloads to pools, yielding promises—fs.promises.readFile in isolates, main-thread yields via Atomics.wait. Threads excel for CPU hogs, but I/O yields context switches, inflating overheads.

Child processes fork interpreters, stdin/stdout pipes async, but spawnSync blocks—IPC for coordination. Anna demos: execSync shells commands, perils in untrusted inputs.

Domains? Deprecated, error silos sans true parallelism. Async_hooks? Context propagation, not computation.

Enter Anna’s brainchild: synchronous workers—native addons spawning interpreters, runUntil blocks main on promises, full API access sans multi-threading. Node 15.5+ requisites, experimental tag.

MongoDB’s Babel transpilation awaits sync-as-call sites, best-effort awaits. Anna’s taxonomy—drawbacks galore—affirms async’s supremacy, yet equips edge cases with informed arsenals.

Experimental Horizons and Practical Caveats

Anna’s holiday hack—runnable on GitHub—invites tinkering, crashes notwithstanding. Her MongoDB pivot underscores sync’s niche: edge functions crave immediacy, transpilation bridges gaps.

Anna’s disquisition, laced with humor, fortifies Node.js fidelity to flux, while charting sync’s shadowed trails.

Links: