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
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-cancel-01.kt).
35
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-cancel-01.kt).
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-cancel-02.kt).
89
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-cancel-02.kt).
90
90
>
91
-
{type="note"}
91
+
{style="note"}
92
92
93
93
Run it to see that it continues to print "I'm sleeping" even after cancellation
94
94
until the job completes by itself after five iterations.
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-cancel-03.kt).
134
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-cancel-03.kt).
135
135
>
136
-
{type="note"}
136
+
{style="note"}
137
137
138
138
While catching `Exception` is an anti-pattern, this issue may surface in more subtle ways, like when using the
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-cancel-04.kt).
176
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-cancel-04.kt).
177
177
>
178
-
{type="note"}
178
+
{style="note"}
179
179
180
180
As you can see, now this loop is cancelled. [isActive] is an extension property
181
181
available inside the coroutine via the [CoroutineScope] object.
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-cancel-05.kt).
221
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-cancel-05.kt).
222
222
>
223
-
{type="note"}
223
+
{style="note"}
224
224
225
225
Both [join][Job.join] and [cancelAndJoin] wait for all finalization actions to complete,
226
226
so the example above produces the following output:
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-cancel-06.kt).
276
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-cancel-06.kt).
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-cancel-07.kt).
314
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-cancel-07.kt).
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-cancel-08.kt).
357
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-cancel-08.kt).
358
358
>
359
-
{type="note"}
359
+
{style="note"}
360
360
361
361
There is no longer an exception when running this code:
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-cancel-09.kt).
418
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-cancel-09.kt).
419
419
>
420
-
{type="note"}
420
+
{style="note"}
421
421
422
422
<!--- CLEAR -->
423
423
@@ -428,7 +428,7 @@ of your machine. You may need to tweak the timeout in this example to actually s
428
428
> since it always happens from the same thread, the one used by `runBlocking`.
429
429
> More on that will be explained in the chapter on coroutine context.
430
430
>
431
-
{type="note"}
431
+
{style="note"}
432
432
433
433
To work around this problem you can store a reference to the resource in a variable instead of returning it
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-cancel-10.kt).
471
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-cancel-10.kt).
472
472
>
473
-
{type="note"}
473
+
{style="note"}
474
474
475
475
This example always prints zero. Resources do not leak.
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-channel-01.kt).
34
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-channel-01.kt).
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-channel-02.kt).
80
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-channel-02.kt).
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-channel-03.kt).
121
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-channel-03.kt).
122
122
>
123
-
{type="note"}
123
+
{style="note"}
124
124
125
125
<!--- TEST
126
126
1
@@ -182,9 +182,9 @@ fun CoroutineScope.square(numbers: ReceiveChannel<Int>): ReceiveChannel<Int> = p
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-channel-04.kt).
185
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-channel-04.kt).
186
186
>
187
-
{type="note"}
187
+
{style="note"}
188
188
189
189
<!--- TEST
190
190
1
@@ -199,7 +199,7 @@ Done!
199
199
> so that we can rely on [structured concurrency](composing-suspending-functions.md#structured-concurrency-with-async) to make
200
200
> sure that we don't have lingering global coroutines in our application.
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-channel-05.kt).
269
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-channel-05.kt).
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-channel-06.kt).
363
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-channel-06.kt).
364
364
>
365
-
{type="note"}
365
+
{style="note"}
366
366
367
367
The output will be similar to the following one, albeit the processor ids that receive
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-channel-07.kt).
438
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-channel-07.kt).
439
439
>
440
-
{type="note"}
440
+
{style="note"}
441
441
442
442
The output is:
443
443
@@ -485,9 +485,9 @@ fun main() = runBlocking<Unit> {
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-channel-08.kt).
488
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-channel-08.kt).
489
489
>
490
-
{type="note"}
490
+
{style="note"}
491
491
492
492
It prints "sending" _five_ times using a buffered channel with capacity of _four_:
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-channel-09.kt).
541
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-channel-09.kt).
542
542
>
543
-
{type="note"}
543
+
{style="note"}
544
544
545
545
The "ping" coroutine is started first, so it is the first one to receive the ball. Even though "ping"
546
546
coroutine immediately starts receiving the ball again after sending it back to the table, the ball gets
@@ -602,9 +602,9 @@ fun main() = runBlocking<Unit> {
> You can get the full code [here](../../kotlinx-coroutines-core/jvm/test/guide/example-channel-10.kt).
605
+
> You can get the full code [here](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/test/guide/example-channel-10.kt).
0 commit comments