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:
- Sets
noExitRuntime=trueto preventexitJSfrom calling_proc_exit(which would abort Asyncify mid-cycle) - Calls
callMain(args)to construct argc/argv on the WASM heap - If the first call unwound (
Asyncify.currData !== null), awaitsAsyncify.whenDone()through the suspend/resume cycles - Catches ExitStatus as normal termination, not an error
Parameters
Section titled “Parameters”module
Section titled “module”An initialized Emscripten module compiled with Asyncify.
string[]
argv passed to the program (argv[0] is excluded per Emscripten convention).
Returns
Section titled “Returns”Promise<number>
The program’s exit code.
Throws
Section titled “Throws”Error if module.Asyncify is undefined.
Caveat
Section titled “Caveat”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.
Example
Section titled “Example”installTTYBridge(module, { input, output })const code = await runWithAsyncify(module, proc.argv.slice(1))