Skip to content

Commit c013459

Browse files
authored
Merge pull request #3394 from Kotlin/feedback-debug-coroutines
update: adding kotlinx.dependencies
2 parents 6cd4ad3 + 8165b5c commit c013459

File tree

2 files changed

+63
-23
lines changed

2 files changed

+63
-23
lines changed

docs/topics/debug-coroutines-with-idea.md

+29-9
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,39 @@ This tutorial demonstrates how to create Kotlin coroutines and debug them using
44

55
The tutorial assumes you have prior knowledge of the [coroutines](coroutines-guide.md) concept.
66

7-
> Debugging works for `kotlinx-coroutines-core` version 1.3.8 or later.
8-
>
9-
{type="note"}
10-
117
## Create coroutines
128

13-
1. Open a Kotlin project in IntelliJ IDEA. If you don't have a project, [create one](jvm-get-started.md#create-an-application).
9+
1. Open a Kotlin project in IntelliJ IDEA. If you don't have a project, [create one](jvm-get-started.md#create-a-project).
10+
2. To use the `kotlinx.coroutines` library in a Gradle project, add the following dependency to `build.gradle(.kts)`:
11+
12+
<tabs group="build-script">
13+
<tab title="Kotlin" group-key="kotlin">
14+
15+
```kotlin
16+
dependencies {
17+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%")
18+
}
19+
```
20+
21+
</tab>
22+
<tab title="Groovy" group-key="groovy">
23+
24+
```groovy
25+
dependencies {
26+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%'
27+
}
28+
```
29+
30+
</tab>
31+
</tabs>
1432

15-
2. Open the `main.kt` file in `src/main/kotlin`.
33+
For other build systems, see instructions in the [`kotlinx.coroutines` README](https://github.com/Kotlin/kotlinx.coroutines#using-in-your-projects).
34+
35+
3. Open the `Main.kt` file in `src/main/kotlin`.
1636

17-
The `src` directory contains Kotlin source files and resources. The `main.kt` file contains sample code that will print `Hello World!`.
37+
The `src` directory contains Kotlin source files and resources. The `Main.kt` file contains sample code that will print `Hello World!`.
1838

19-
3. Change code in the `main()` function:
39+
4. Change code in the `main()` function:
2040

2141
* Use the [`runBlocking()`](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html) block to wrap a coroutine.
2242
* Use the [`async()`](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/async.html) function to create coroutines that compute deferred values `a` and `b`.
@@ -39,7 +59,7 @@ The tutorial assumes you have prior knowledge of the [coroutines](coroutines-gui
3959
}
4060
```
4161

42-
4. Build the code by clicking **Build Project**.
62+
5. Build the code by clicking **Build Project**.
4363

4464
![Build an application](flow-build-project.png)
4565

docs/topics/debug-flow-with-idea.md

+34-14
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,41 @@ This tutorial demonstrates how to create Kotlin Flow and debug it using IntelliJ
44

55
The tutorial assumes you have prior knowledge of the [coroutines](coroutines-guide.md) and [Kotlin Flow](flow.md#flows) concepts.
66

7-
> Debugging works for `kotlinx-coroutines-core` version 1.3.8 or later.
8-
>
9-
{type="note"}
10-
117
## Create a Kotlin flow
128

139
Create a Kotlin [flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/flow.html) with a slow emitter and a slow collector:
1410

15-
1. Open a Kotlin project in IntelliJ IDEA. If you don't have a project, [create one](jvm-get-started.md#create-an-application).
16-
17-
2. Open the `main.kt` file in `src/main/kotlin`.
18-
19-
The `src` directory contains Kotlin source files and resources. The `main.kt` file contains sample code that will print `Hello World!`.
20-
21-
3. Create the `simple()` function that returns a flow of three numbers:
11+
1. Open a Kotlin project in IntelliJ IDEA. If you don't have a project, [create one](jvm-get-started.md#create-a-project).
12+
2. To use the `kotlinx.coroutines` library in a Gradle project, add the following dependency to `build.gradle(.kts)`:
13+
14+
<tabs group="build-script">
15+
<tab title="Kotlin" group-key="kotlin">
16+
17+
```kotlin
18+
dependencies {
19+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%")
20+
}
21+
```
22+
23+
</tab>
24+
<tab title="Groovy" group-key="groovy">
25+
26+
```groovy
27+
dependencies {
28+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%'
29+
}
30+
```
31+
32+
</tab>
33+
</tabs>
34+
35+
For other build systems, see instructions in the [`kotlinx.coroutines` README](https://github.com/Kotlin/kotlinx.coroutines#using-in-your-projects).
36+
37+
3. Open the `Main.kt` file in `src/main/kotlin`.
38+
39+
The `src` directory contains Kotlin source files and resources. The `Main.kt` file contains sample code that will print `Hello World!`.
40+
41+
4. Create the `simple()` function that returns a flow of three numbers:
2242

2343
* Use the [`delay()`](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/delay.html) function to imitate CPU-consuming blocking code. It suspends the coroutine for 100 ms without blocking the thread.
2444
* Produce the values in the `for` loop using the [`emit()`](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow-collector/emit.html) function.
@@ -36,7 +56,7 @@ Create a Kotlin [flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-cor
3656
}
3757
```
3858

39-
4. Change the code in the `main()` function:
59+
5. Change the code in the `main()` function:
4060

4161
* Use the [`runBlocking()`](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html) block to wrap a coroutine.
4262
* Collect the emitted values using the [`collect()`](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect.html) function.
@@ -53,7 +73,7 @@ Create a Kotlin [flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-cor
5373
}
5474
```
5575

56-
5. Build the code by clicking **Build Project**.
76+
6. Build the code by clicking **Build Project**.
5777

5878
![Build an application](flow-build-project.png)
5979

@@ -84,7 +104,7 @@ Create a Kotlin [flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-cor
84104

85105
## Add a concurrently running coroutine
86106

87-
1. Open the `main.kt` file in `src/main/kotlin`.
107+
1. Open the `Main.kt` file in `src/main/kotlin`.
88108

89109
2. Enhance the code to run the emitter and collector concurrently:
90110

0 commit comments

Comments
 (0)