Marc
07/08/2025, 2:10 PM@JsExport
only works on classes that exclusively use non-suspending functions. Is there a way to transform the suspending functions into functions returning promises automatically? In case I need to do it manually I am also not quite sure how to do that, since I want to mostly keep the existing class but only transform a couple of suspending functions to promises.broadway_lamb
07/08/2025, 2:15 PMbroadway_lamb
07/08/2025, 2:19 PMsuspend
functions into Promise
-returning ones: https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-pluginMarc
07/08/2025, 2:22 PMMarc
07/08/2025, 2:26 PMbroadway_lamb
07/08/2025, 2:36 PM-Xes-generators
compiler flag if you are compiling to ES5.
If your target is ES2015, then it should be enabled by default.
See https://kotlinlang.org/docs/gradle-compiler-options.html on how to pass compiler flags and set the target JS edition.Marc
07/08/2025, 2:47 PMDeclaration of such kind (suspend function) cannot be exported to JavaScript.
error when it should be trying to compile the function to generators does not make a lot of sense.broadway_lamb
07/08/2025, 2:48 PMsuspend
functions, but it still doesn't allow them to be exported to JavaScript.Marc
07/08/2025, 2:56 PMEdoardo Luppi
07/08/2025, 3:53 PMIn case I need to do it manually I am also not quite sure how to do thatIf it can help you, somehow, just know that we maintain a separate layer for exposing a subset of our API to JS or Java consumers. We have separate modules, that depend on the "core" module, and that wrap the suspending functions. See the screenshot. It's important to keep in mind that you must take into account the coroutine scope in real world scenarios. You can't just slap in a
GlobalScope
. I mean you can, but it's most likely suboptimal.Edoardo Luppi
07/08/2025, 3:54 PMZDeferred
symbol maps to a Promise
under JS, and to a CompletableFuture
under Java.Edoardo Luppi
07/08/2025, 3:57 PM