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
* Flow guide by example
* Consistent chapter naming and ordering in docs
* Make "supervision" a subsection of "Exception Handling" chapter
* Knit: filter out sampleStart/End from Knit-generated source files
* Knit: Support example auto-numbering
* <aname='your-first-coroutine'></a>[Your first coroutine](docs/basics.md#your-first-coroutine)
8
8
* <aname='bridging-blocking-and-non-blocking-worlds'></a>[Bridging blocking and non-blocking worlds](docs/basics.md#bridging-blocking-and-non-blocking-worlds)
9
9
* <aname='waiting-for-a-job'></a>[Waiting for a job](docs/basics.md#waiting-for-a-job)
@@ -13,22 +13,22 @@ The main coroutines guide has moved to the [docs folder](docs/coroutines-guide.m
13
13
* <aname='coroutines-are-light-weight'></a>[Coroutines ARE light-weight](docs/basics.md#coroutines-are-light-weight)
14
14
* <aname='global-coroutines-are-like-daemon-threads'></a>[Global coroutines are like daemon threads](docs/basics.md#global-coroutines-are-like-daemon-threads)
* <aname='structured-concurrency-with-async'></a>[Structured concurrency with async](docs/composing-suspending-functions.md#structured-concurrency-with-async)
* <aname='coroutine-context-and-dispatchers'></a>[Coroutine context and dispatchers](docs/coroutine-context-and-dispatchers.md#coroutine-context-and-dispatchers)
31
+
* <aname='coroutine-context-and-dispatchers'></a>[Coroutine Context and Dispatchers](docs/coroutine-context-and-dispatchers.md#coroutine-context-and-dispatchers)
32
32
* <aname='dispatchers-and-threads'></a>[Dispatchers and threads](docs/coroutine-context-and-dispatchers.md#dispatchers-and-threads)
33
33
* <aname='unconfined-vs-confined-dispatcher'></a>[Unconfined vs confined dispatcher](docs/coroutine-context-and-dispatchers.md#unconfined-vs-confined-dispatcher)
34
34
* <aname='debugging-coroutines-and-threads'></a>[Debugging coroutines and threads](docs/coroutine-context-and-dispatchers.md#debugging-coroutines-and-threads)
@@ -40,16 +40,45 @@ The main coroutines guide has moved to the [docs folder](docs/coroutines-guide.m
* <aname='exceptions-in-supervised-coroutines'></a>[Exceptions in supervised coroutines](docs/exception-handling.md#exceptions-in-supervised-coroutines)
* <aname='exceptions-in-supervised-coroutines'></a>[Exceptions in supervised coroutines](docs/exception-handling.md#exceptions-in-supervised-coroutines)
* <aname='shared-mutable-state-and-concurrency'></a>[Shared mutable state and concurrency](docs/shared-mutable-state-and-concurrency.md#shared-mutable-state-and-concurrency)
*[Exceptions in supervised coroutines](#exceptions-in-supervised-coroutines)
27
+
*[Supervision](#supervision)
28
+
*[Supervision job](#supervision-job)
29
+
*[Supervision scope](#supervision-scope)
30
+
*[Exceptions in supervised coroutines](#exceptions-in-supervised-coroutines)
31
31
32
32
<!--- END_TOC -->
33
33
34
-
## Exception handling
34
+
## Exception Handling
35
35
36
36
37
37
This section covers exception handling and cancellation on exceptions.
@@ -355,7 +355,7 @@ Caught original java.io.IOException
355
355
```
356
356
<!--- TEST-->
357
357
358
-
## Supervision
358
+
###Supervision
359
359
360
360
As we have studied before, cancellation is a bidirectional relationship propagating through the whole
361
361
coroutines hierarchy. But what if unidirectional cancellation is required?
@@ -367,7 +367,7 @@ but if UI component is destroyed (and its job is cancelled), then it is necessar
367
367
Another example is a server process that spawns several children jobs and needs to _supervise_
368
368
their execution, tracking their failures and restarting just those children jobs that had failed.
369
369
370
-
### Supervision job
370
+
####Supervision job
371
371
372
372
For these purposes [SupervisorJob][SupervisorJob()] can be used. It is similar to a regular [Job][Job()] with the only exception that cancellation is propagated
373
373
only downwards. It is easy to demonstrate with an example:
@@ -421,7 +421,7 @@ Second child is cancelled because supervisor is cancelled
421
421
<!--- TEST-->
422
422
423
423
424
-
### Supervision scope
424
+
####Supervision scope
425
425
426
426
For *scoped* concurrency [supervisorScope] can be used instead of [coroutineScope] for the same purpose. It propagates cancellation
427
427
only in one direction and cancels all children only if it has failed itself. It also waits for all children before completion
@@ -469,7 +469,7 @@ Caught assertion error
469
469
```
470
470
<!--- TEST-->
471
471
472
-
### Exceptions in supervised coroutines
472
+
####Exceptions in supervised coroutines
473
473
474
474
Another crucial difference between regular and supervisor jobs is exception handling.
475
475
Every child should handle its exceptions by itself via exception handling mechanisms.
0 commit comments