You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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`.
16
36
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!`.
18
38
19
-
3. Change code in the `main()` function:
39
+
4. Change code in the `main()` function:
20
40
21
41
* Use the [`runBlocking()`](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html) block to wrap a coroutine.
22
42
* 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
Copy file name to clipboardExpand all lines: docs/topics/debug-flow-with-idea.md
+34-14
Original file line number
Diff line number
Diff line change
@@ -4,21 +4,41 @@ This tutorial demonstrates how to create Kotlin Flow and debug it using IntelliJ
4
4
5
5
The tutorial assumes you have prior knowledge of the [coroutines](coroutines-guide.md) and [Kotlin Flow](flow.md#flows) concepts.
6
6
7
-
> Debugging works for `kotlinx-coroutines-core` version 1.3.8 or later.
8
-
>
9
-
{type="note"}
10
-
11
7
## Create a Kotlin flow
12
8
13
9
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:
14
10
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)`:
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:
22
42
23
43
* 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.
24
44
* 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
36
56
}
37
57
```
38
58
39
-
4. Change the code in the `main()` function:
59
+
5. Change the code in the `main()` function:
40
60
41
61
*Use the [`runBlocking()`](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html) block to wrap a coroutine.
42
62
*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
53
73
}
54
74
```
55
75
56
-
5. Build the code by clicking **BuildProject**.
76
+
6. Build the code by clicking **BuildProject**.
57
77
58
78

59
79
@@ -84,7 +104,7 @@ Create a Kotlin [flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-cor
84
104
85
105
## Add a concurrently running coroutine
86
106
87
-
1. Open the `main.kt` file in `src/main/kotlin`.
107
+
1. Open the `Main.kt` file in `src/main/kotlin`.
88
108
89
109
2. Enhance the code to run the emitter and collector concurrently:
0 commit comments