# Howto use coroutines in M1.3

**URL:** <https://discuss.kotlinlang.org/t/howto-use-coroutines-in-m1-3/9603>\
**Category:** Support\
**Created:** [September 28, 2018, 1:33pm UTC](https://discuss.kotlinlang.org/t/howto-use-coroutines-in-m1-3/9603 "2018-09-28T13:33:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tango24](https://avatars.discourse-cdn.com/v4/letter/t/74df32/32.png) [@tango24](https://discuss.kotlinlang.org/u/tango24)\
**Post date:** [September 28, 2018, 1:33pm UTC](https://discuss.kotlinlang.org/t/howto-use-coroutines-in-m1-3/9603/1 "2018-09-28T13:33:53Z")

</div>

What is the right way to use coroutines under M1.3 (EAP)?  
I am obviously missing some basic ingredience, because coroutine “hello-world”

```auto
fun main(args: Array<String>) {
     launch {
        delay(1000)
        println("Hello")
    }
}

```

will not compile. `launch` and `delay` cannot be resolved.

The following are my kotlin related parts from `build.gradle.kts`

```auto
plugins {
    kotlin("jvm") version "1.3.0-rc-116"
}

apply {
    plugin("kotlin")
}

kotlin {
    experimental {
        coroutines = Coroutines.ENABLE
    }
}

dependencies {
    compile(kotlin("stdlib-jdk8"))
}

tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "1.8"
}

```

I guess, the `experimental` part is no longer needed in 1.3.

---

<div class="post-metadata">

**Author:** ![fatjoe79](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fatjoe79/32/4221_2.png) [@fatjoe79](https://discuss.kotlinlang.org/u/fatjoe79)\
**Post date:** [September 28, 2018, 1:47pm UTC](https://discuss.kotlinlang.org/t/howto-use-coroutines-in-m1-3/9603/2 "2018-09-28T13:47:27Z")

</div>

You need to import launch and delay I believe. They are not keywords in the language, but rather functions defined in some package.

---

<div class="post-metadata">

**Author:** ![tango24](https://avatars.discourse-cdn.com/v4/letter/t/74df32/32.png) [@tango24](https://discuss.kotlinlang.org/u/tango24)\
**Post date:** [September 28, 2018, 4:22pm UTC](https://discuss.kotlinlang.org/t/howto-use-coroutines-in-m1-3/9603/3 "2018-09-28T16:22:36Z")

</div>

Unfortunately, they are not available as imports (`launch` will only autocomplete to `javafx.application.Application.launch`).  
Other functions from the corouting package like `suspendCoroutine` are available, that is why I believe something is missing in the configuration (jvm specific intrinsics?).

---

<div class="post-metadata">

**Author:** ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)\
**Post date:** [September 28, 2018, 4:34pm UTC](https://discuss.kotlinlang.org/t/howto-use-coroutines-in-m1-3/9603/4 "2018-09-28T16:34:55Z")

</div>

You need to add a dependency on [`kotlinx.coroutines`](https://github.com/Kotlin/kotlinx.coroutines/#using-in-your-projects) library, where these functions are declared.

The latest version of that library for Kotlin 1.3 is `0.27.0-eap13`.

Note that the top-level `launch` and `async` functions are deprecated, you can find how to use them properly here: [Structured concurrency. Today marks the release of a version… | by Roman Elizarov | Medium](https://medium.com/@elizarov/structured-concurrency-722d765aa952)

---

<div class="post-metadata">

**Author:** ![tango24](https://avatars.discourse-cdn.com/v4/letter/t/74df32/32.png) [@tango24](https://discuss.kotlinlang.org/u/tango24)\
**Post date:** [October 1, 2018, 10:13am UTC](https://discuss.kotlinlang.org/t/howto-use-coroutines-in-m1-3/9603/5 "2018-10-01T10:13:15Z")

</div>

Thank you. It works now.

---

<div class="post-metadata">

**Author:** ![Tim\_van\_der\_Leeuw.1](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/tim_van_der_leeuw.1/32/9155_2.png) [@Tim\_van\_der\_Leeuw.1](https://discuss.kotlinlang.org/u/Tim_van_der_Leeuw.1)\
**Post date:** [November 9, 2018, 8:49am UTC](https://discuss.kotlinlang.org/t/howto-use-coroutines-in-m1-3/9603/6 "2018-11-09T08:49:46Z")

</div>

Reading that article I’m now finally getting a grasp on how to use coroutines in Kotlin 1.3.

The documentation doesn’t seem to do a very good job to me of explaining how to use coroutines other than giving `runBlocking()` which is not what I wanted, and didn’t do a very good job at all (in my opinion) of explaining how to use `GlobalScope` or how to use the new version of `launch()` with a `CoroutineScope`.

It doesn’t help of course that almost all articles, posts and code examples that one finds are using coroutines from Kotlin 1.1 or 1.2.

I think a few more introductory articles in the manual on how to implement `CoroutineScope`, how to supply a `CoroutineContext`, what dispatchers to choose from etc wouldn’t be amiss.
