WASM/SimConnect and Asynchronous execution

WASM code runs on the main thread. Multithreading was requested some time ago but is not available yet. About WASM and threads

SimConnect is available in-process in the sim (via wasm) or out-of-process (another EXE on the computer). SimConnect calls are asynchronous either way. When you get a callback it will be executed on the main thread at the next available opportunity.

Some options you might have:

  • Use JS fetch API to retrieve data, which is asynchronous.
  • Use WASM network API, which is probably asynchronous.
  • Use WASM I/O on the main thread, but read the data over a range of frames instead of all on one frame. This probably reduces the delay but ultimately I/O on the main thread is unacceptable due to latency.
  • Use an external program

I don’t think any async I/O is available in WASM but I would be very happy to be corrected on that point.