@@ -22,7 +22,7 @@ fun main(args: Array<String>) {
22
22
Run this code:
23
23
24
24
```
25
- Hello!
25
+ Hello,
26
26
World!
27
27
```
28
28
@@ -60,9 +60,9 @@ fun main(args: Array<String>) = runBlocking { // start main coroutine
60
60
The result is the same, but this code uses only non-blocking ` delay ` .
61
61
62
62
` runBlocking { ... } ` works as an adaptor that is used here to start the top-level main coroutine.
63
- The regular code outside of ` runBlocking ` _ blocks_ , until the coroutine inside ` runBlocking ` works .
63
+ The regular code outside of ` runBlocking ` _ blocks_ , until the coroutine inside ` runBlocking ` is active .
64
64
65
- This is also how you write unit-test for suspending functions:
65
+ This is also a way to write unit-tests for suspending functions:
66
66
67
67
``` kotlin
68
68
class MyTest {
@@ -76,7 +76,7 @@ class MyTest {
76
76
## Waiting for a job
77
77
78
78
Delaying for a time while a _ child_ coroutine is working is not a good approach. Let's explicitly
79
- wait (in a non-blocking way) until other coroutine that we have launched is complete:
79
+ wait (in a non-blocking way) until the other coroutine that we have launched is complete:
80
80
81
81
``` kotlin
82
82
fun main (args : Array <String >) = runBlocking {
@@ -85,7 +85,7 @@ fun main(args: Array<String>) = runBlocking {
85
85
println (" World!" )
86
86
}
87
87
println (" Hello," )
88
- job.join() // wait until children coroutine completes
88
+ job.join() // wait until child coroutine completes
89
89
}
90
90
```
91
91
@@ -96,8 +96,8 @@ the child coroutine in any way. Much better.
96
96
97
97
## Extract function refactoring
98
98
99
- Let's extract the block of code inside ` launch(Here} { ... } ` into a separate function. If you
100
- perform "Extract function" refactoring, you'll get a new function with ` suspend ` modifier.
99
+ Let's extract the block of code inside ` launch(Here} { ... } ` into a separate function. When you
100
+ perform "Extract function" refactoring on this code you get a new function with ` suspend ` modifier.
101
101
That is your first _ suspending function_ . Suspending functions can be used inside coroutines
102
102
just like regular functions, but their additional feature is that they can, in turn,
103
103
use other suspending functions, like ` delay ` in this example, to _ suspend_ execution of a coroutine.
0 commit comments