Hi. I am working with multiplatform library (based...
# javascript
k
Hi. I am working with multiplatform library (based on 1.4.21) and struck with suspend functions. I can't find any info how to use them from JS. I can see them from JS code, but I get an error when I am calling them.
Cannot read property context
I see that method signature in JS has additional param - continuation. How should I use it?
m
You can’t use
suspend fun
directly from JS. Exported functions need to use
Promise
instead and not be
suspend
.
j
Not sure exactly whether it was pure JS or not you were thinking of but you can use them from Kotlin/JS....have example of this in following https://github.com/joreilly/PeopleInSpace/blob/master/web/src/main/kotlin/App.kt
k
But promises is only for JS. How can I use them in common module? To use the same code for all targets (Android, ios, js)
m
You use
suspend fun
in common code and add
Promise
functions that wrap the
suspend fun
only for the JS target.
👍 1
l
Hi folks. Can anyone show me an example of this? Some repository? (wrap the suspend fun only for the JS target...).