I'm running a C tool compiled to wasm using emscripten. The tool works on very large files. When running this tool normally on the CLI, often operations stream the results and terminate the program early once enough data has been returned. For example you might run:
./tool <input-file> | head -n 100
The tool would terminate after it detects stdout has been closed by head
, effectively only reading a small portion of the input.
The problem is that stdout with emscripten appears to be asynchronous (by overriding Module.print), so the tool runs to completion every time. Is there a way to make it block on stdout so I can only read as much as I need and then terminate the tool?