Skip to content

installTTYBridge

installTTYBridge(module, options): void

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

Install custom TTY ops on an Emscripten module so that stdin reads suspend via Asyncify and resume when input arrives.

Replaces the default get_char, put_char, fsync, and ioctl_* handlers on both the console (major=5) and stderr (major=6) TTY devices, wires a 1-byte-per-call TTY.stream_ops.read (see caveat), and installs an Asyncify-aware poll on stdin so select() works with async input.

Call this AFTER module init but BEFORE calling _main().

EmscriptenModule

An initialized Emscripten module compiled with Asyncify + TTY.

TTYBridgeOptions

Input source, output sink, and optional terminal size. See TTYBridgeOptions.

void

Error if module.Asyncify is undefined — the module was not compiled with -sASYNCIFY.

Error if module.TTY is undefined — TTY is not in EXPORTED_RUNTIME_METHODS.

The default TTY read loop calls get_char until the buffer fills, which triggers a double-Asyncify-unwind and crashes. The 1-byte read override forces fd_read to return to WASM after each byte.

const queue = createInputQueue()
const output = createBufferedOutput(chunk => proc.stdout.write(chunk))
installTTYBridge(module, { input: queue, output })
await runWithAsyncify(module, args)