Hi,
I'm trying to compile a number of command-line applications to WebAssembly via Emscripten, but along the way I realized that synchronous invocation of these commands is a must. After some inspection, I've come to realize that the main drawback is using WebAssembly.instantiate, an async/Promise function.
Right now, I pre-download a module using XHR and pass it through WebAssembly.compile, then passing that compiled module to WebAssembly.instantiate every time this command-line app needs to be run. Unfortunately, both aren't synchronous.
To illustrate, if I wanted to call ls three times in a row, I'd call the following functions:
execSync("ls");
execSync("ls");
execSync("ls");
The problem is that each time ls is run, it needs to be instantiated again (WebAssembly.instantiate) to give it a clean state, which breaks the synchronous nature of this code (I don't like this either, but it is what it is). Is there a way that I can instantiate it just once and reuse that for all subsequent invocations? Are there any hidden "gotchas," like dirty memory that needs to be cleared or WASM globals that need to be set to 0?
Thanks in advance!
Hi,
I'm trying to compile a number of command-line applications to WebAssembly via Emscripten, but along the way I realized that synchronous invocation of these commands is a must. After some inspection, I've come to realize that the main drawback is using
WebAssembly.instantiate, an async/Promisefunction.Right now, I pre-download a module using XHR and pass it through
WebAssembly.compile, then passing that compiled module toWebAssembly.instantiateevery time this command-line app needs to be run. Unfortunately, both aren't synchronous.To illustrate, if I wanted to call
lsthree times in a row, I'd call the following functions:The problem is that each time
lsis run, it needs to be instantiated again (WebAssembly.instantiate) to give it a clean state, which breaks the synchronous nature of this code (I don't like this either, but it is what it is). Is there a way that I can instantiate it just once and reuse that for all subsequent invocations? Are there any hidden "gotchas," like dirty memory that needs to be cleared or WASM globals that need to be set to 0?Thanks in advance!