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.
Alexey Zolotarev
02/27/2025, 7:30 AM
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
bashor
03/04/2025, 10:52 PM
There is no special support for JS Promise in the “core” (compiler+stdlib).
kotlinx-coroutines has a some support for JS Promise.