Skip to content

runWithAsyncify

runWithAsyncify(module, args?): Promise<number>

Defined in: packages/runtime/src/wasm/tty-bridge.ts:841

Run an Emscripten program’s main() using Asyncify for suspend/resume.

Replaces the standard callMain() pattern for modules that perform async stdin I/O via the TTY bridge. It:

  1. Sets noExitRuntime=true to prevent exitJS from calling _proc_exit (which would abort Asyncify mid-cycle)
  2. Calls callMain(args) to construct argc/argv on the WASM heap
  3. If the first call unwound (Asyncify.currData !== null), awaits Asyncify.whenDone() through the suspend/resume cycles
  4. Catches ExitStatus as normal termination, not an error

EmscriptenModule

An initialized Emscripten module compiled with Asyncify.

string[]

argv passed to the program (argv[0] is excluded per Emscripten convention).

Promise<number>

The program’s exit code.

Error if module.Asyncify is undefined.

whenDone() must be called AFTER an async operation is in progress, not before — we only await it when the initial callMain returned with currData set.

installTTYBridge(module, { input, output })
const code = await runWithAsyncify(module, proc.argv.slice(1))