https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
m

Mark

12/07/2017, 3:41 AM
Hey @elizarov or any other helpful friends, I'm currently messing around with a multi-platform project and I am trying to get coroutines up and running. I have
kotlinx-corountines-core
imported through my common module and I have been successfully using it transitively in the JVM project (a little TornadoFx visualizer) to do a bit of processing off of the main thread. However, I am now trying to speed up some of the common logic and I've just started getting an unresolved reference to
kotlinx
,
runBlocking
and
launch
when compiling the common module. Is there something special I need to do in the Gradle imports to ensure that I am getting an implementation of coroutines that is compatible with Kotlin common? Some other trick that I am missing?
g

gildor

12/07/2017, 3:43 AM
kotlinx.coroutines now available only for JVM and cannot be used in common module
But you can write platform specific implementation of suspend function
m

Mark

12/07/2017, 3:44 AM
That'd do it, thanks so much for the fast reply. Seems like the right path forward
g

gildor

12/07/2017, 3:45 AM
processing off of the main thread
Because for example this is just impossible for JS which is single-thread language
m

Mark

12/07/2017, 3:45 AM
Right, makes sense
g

gildor

12/07/2017, 3:46 AM
But you can use coroutines in common module, but you need different coroutine builders for different platforms
m

Mark

12/07/2017, 3:50 AM
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines.experimental/index.html So basically, everything that is listed in the 'ALL' dropdown here should be safe to use?
g

gildor

12/07/2017, 4:10 AM
Everything in kotlin.coroutines package available for the all platforms, but particular implementation kotlinX.coroutines is jvm.
Actually not all components of kotlinx.coroutines make sense for all platforms, like runBlocking for example for js or any other thread related stuff
m

Mark

12/08/2017, 3:42 AM
Got it, was missing the kotlin vs kotlinx subtlety
3 Views