Hey, Kotlin coroutines for Wasm/JS support JS prom...
# webassembly
a
Hey, Kotlin coroutines for Wasm/JS support JS promises. How do they work internally? For example, when Kotlin imports a JS function that returns a promise, how does the Wasm module get notified when the promise is resolved on the JS side? Also how is a promise represented as a native Wasm type when passed from JS to Kotlin initially? Asking in the context of implementing a similar feature for the WasmWasi target. The coroutines library supports the target, and theoretically, it should be possible to implement a feature similar to the interop with JS promises for the browser. For instance, on the host side there could be some sort of Future.
I see that Promises are passed as
externref
from JS host to Kotlin guest. And it is impossible to do that with Wasm/Wasi since there is no support for this type in
@WasiImport
b
There is no special support for JS Promise in the “core” (compiler+stdlib). kotlinx-coroutines has a some support for JS Promise.