@@ -47,7 +47,7 @@ Run the following code:
47
47
import kotlinx.coroutines.*
48
48
49
49
fun main () {
50
- GlobalScope .launch { // launch new coroutine in background and continue
50
+ GlobalScope .launch { // launch a new coroutine in background and continue
51
51
delay(1000L ) // non-blocking delay for 1 second (default time unit is ms)
52
52
println (" World!" ) // print after delay
53
53
}
@@ -58,7 +58,7 @@ fun main() {
58
58
59
59
</div >
60
60
61
- > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-01.kt )
61
+ > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-01.kt ) .
62
62
63
63
You will see the following result:
64
64
@@ -98,7 +98,7 @@ Let's be explicit about blocking using [runBlocking] coroutine builder:
98
98
import kotlinx.coroutines.*
99
99
100
100
fun main () {
101
- GlobalScope .launch { // launch new coroutine in background and continue
101
+ GlobalScope .launch { // launch a new coroutine in background and continue
102
102
delay(1000L )
103
103
println (" World!" )
104
104
}
@@ -111,7 +111,7 @@ fun main() {
111
111
112
112
</div >
113
113
114
- > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-02.kt )
114
+ > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-02.kt ) .
115
115
116
116
<!-- - TEST
117
117
Hello,
@@ -130,7 +130,7 @@ the execution of the main function:
130
130
import kotlinx.coroutines.*
131
131
132
132
fun main () = runBlocking<Unit > { // start main coroutine
133
- GlobalScope .launch { // launch new coroutine in background and continue
133
+ GlobalScope .launch { // launch a new coroutine in background and continue
134
134
delay(1000L )
135
135
println (" World!" )
136
136
}
@@ -141,7 +141,7 @@ fun main() = runBlocking<Unit> { // start main coroutine
141
141
142
142
</div >
143
143
144
- > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-02b.kt )
144
+ > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-02b.kt ) .
145
145
146
146
<!-- - TEST
147
147
Hello,
@@ -184,7 +184,7 @@ import kotlinx.coroutines.*
184
184
185
185
fun main () = runBlocking {
186
186
// sampleStart
187
- val job = GlobalScope .launch { // launch new coroutine and keep a reference to its Job
187
+ val job = GlobalScope .launch { // launch a new coroutine and keep a reference to its Job
188
188
delay(1000L )
189
189
println (" World!" )
190
190
}
@@ -196,7 +196,7 @@ fun main() = runBlocking {
196
196
197
197
</div >
198
198
199
- > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-03.kt )
199
+ > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-03.kt ) .
200
200
201
201
<!-- - TEST
202
202
Hello,
@@ -231,7 +231,7 @@ in its scope complete. Thus, we can make our example simpler:
231
231
import kotlinx.coroutines.*
232
232
233
233
fun main () = runBlocking { // this: CoroutineScope
234
- launch { // launch new coroutine in the scope of runBlocking
234
+ launch { // launch a new coroutine in the scope of runBlocking
235
235
delay(1000L )
236
236
println (" World!" )
237
237
}
@@ -241,7 +241,7 @@ fun main() = runBlocking { // this: CoroutineScope
241
241
242
242
</div >
243
243
244
- > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-03s.kt )
244
+ > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-03s.kt ) .
245
245
246
246
<!-- - TEST
247
247
Hello,
@@ -272,16 +272,16 @@ fun main() = runBlocking { // this: CoroutineScope
272
272
}
273
273
274
274
delay(100L )
275
- println (" Task from coroutine scope" ) // This line will be printed before nested launch
275
+ println (" Task from coroutine scope" ) // This line will be printed before the nested launch
276
276
}
277
277
278
- println (" Coroutine scope is over" ) // This line is not printed until nested launch completes
278
+ println (" Coroutine scope is over" ) // This line is not printed until the nested launch completes
279
279
}
280
280
```
281
281
282
282
</div >
283
283
284
- > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-04.kt )
284
+ > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-04.kt ) .
285
285
286
286
<!-- - TEST
287
287
Task from coroutine scope
@@ -317,7 +317,7 @@ suspend fun doWorld() {
317
317
318
318
</div >
319
319
320
- > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-05.kt )
320
+ > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-05.kt ) .
321
321
322
322
<!-- - TEST
323
323
Hello,
@@ -328,10 +328,10 @@ World!
328
328
But what if the extracted function contains a coroutine builder which is invoked on the current scope?
329
329
In this case ` suspend ` modifier on the extracted function is not enough. Making ` doWorld ` extension
330
330
method on ` CoroutineScope ` is one of the solutions, but it may not always be applicable as it does not make API clearer.
331
- Idiomatic solution is to have either explicit ` CoroutineScope ` as a field in a class containing target function
332
- or implicit when outer class implements ` CoroutineScope ` .
331
+ The idiomatic solution is to have either an explicit ` CoroutineScope ` as a field in a class containing the target function
332
+ or an implicit one when the outer class implements ` CoroutineScope ` .
333
333
As a last resort, [ CoroutineScope(coroutineContext)] [ CoroutineScope() ] can be used, but such approach is structurally unsafe
334
- because you no longer have control on the scope this method is executed . Only private API can use this builder.
334
+ because you no longer have control on the scope of execution of this method . Only private APIs can use this builder.
335
335
336
336
### Coroutines ARE light-weight
337
337
@@ -354,7 +354,7 @@ fun main() = runBlocking {
354
354
355
355
</div >
356
356
357
- > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-06.kt )
357
+ > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-06.kt ) .
358
358
359
359
<!-- - TEST lines.size == 1 && lines[0] == ".".repeat(100_000) -->
360
360
@@ -386,7 +386,7 @@ fun main() = runBlocking {
386
386
387
387
</div >
388
388
389
- > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-07.kt )
389
+ > You can get full code [ here] ( ../kotlinx-coroutines-core/jvm/test/guide/example-basic-07.kt ) .
390
390
391
391
You can run and see that it prints three lines and terminates:
392
392
0 commit comments