7

Is it possible to launch any coroutines when targeting JavaScript? It doesn't like any of the usual ways like async{}

Example on: https://github.com/thigg/no-kotlinx-in-js

thi gg
  • 1,969
  • 2
  • 22
  • 47

1 Answers1

7

Yes, you can. Take a look at example-frontend-js — frontend application written in Kotlin/JS that uses coroutines to implement animations in imperative style.

Don't forget to add a dependency on org.jetbrains.kotlinx:kotlinx-coroutines-core in your Gradle configs.

madhead
  • 31,729
  • 16
  • 153
  • 201
  • 2
    Im on Kotlin 1.3.41. I created a Kotlin JS Project with intellij idea and it says there is no package `import kotlinx.coroutines.*`. Did I get any config wrong? – thi gg Aug 03 '19 at 22:21
  • Can't spot differences so far, they seem simply to include the stdlib, nothing else. I'm doing the same as far as I can see. I will build a minimal failing example... – thi gg Aug 03 '19 at 22:59
  • I created a minimal-not-working-example: https://github.com/thigg/no-kotlinx-in-js maybe you can help me to spot what I am doing wrong? – thi gg Aug 03 '19 at 23:14
  • 1
    You don't have all the dependencies they have in a sample project. Take a look at parent's build.gradle: https://github.com/Kotlin/kotlinx.coroutines/blob/master/build.gradle#L130. That `allprojects` configure additional dependencies and plugins. – madhead Aug 03 '19 at 23:51
  • 1
    Yes, it was the missing import. Thanks. Will you update your answer? – thi gg Aug 04 '19 at 11:13