Skip to content

Commit 3258e1f

Browse files
elizarovqwwdfsad
authored andcommitted
Flow docs (#1432)
* 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
1 parent 3807a74 commit 3258e1f

File tree

100 files changed

+3199
-161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+3199
-161
lines changed

coroutines-guide.md

+54-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ The main coroutines guide has moved to the [docs folder](docs/coroutines-guide.m
33
## Table of contents
44

55
<!--- TOC_REF docs/basics.md -->
6-
* <a name='coroutine-basics'></a>[Coroutine basics](docs/basics.md#coroutine-basics)
6+
* <a name='coroutine-basics'></a>[Coroutine Basics](docs/basics.md#coroutine-basics)
77
* <a name='your-first-coroutine'></a>[Your first coroutine](docs/basics.md#your-first-coroutine)
88
* <a name='bridging-blocking-and-non-blocking-worlds'></a>[Bridging blocking and non-blocking worlds](docs/basics.md#bridging-blocking-and-non-blocking-worlds)
99
* <a name='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
1313
* <a name='coroutines-are-light-weight'></a>[Coroutines ARE light-weight](docs/basics.md#coroutines-are-light-weight)
1414
* <a name='global-coroutines-are-like-daemon-threads'></a>[Global coroutines are like daemon threads](docs/basics.md#global-coroutines-are-like-daemon-threads)
1515
<!--- TOC_REF docs/cancellation-and-timeouts.md -->
16-
* <a name='cancellation-and-timeouts'></a>[Cancellation and timeouts](docs/cancellation-and-timeouts.md#cancellation-and-timeouts)
16+
* <a name='cancellation-and-timeouts'></a>[Cancellation and Timeouts](docs/cancellation-and-timeouts.md#cancellation-and-timeouts)
1717
* <a name='cancelling-coroutine-execution'></a>[Cancelling coroutine execution](docs/cancellation-and-timeouts.md#cancelling-coroutine-execution)
1818
* <a name='cancellation-is-cooperative'></a>[Cancellation is cooperative](docs/cancellation-and-timeouts.md#cancellation-is-cooperative)
1919
* <a name='making-computation-code-cancellable'></a>[Making computation code cancellable](docs/cancellation-and-timeouts.md#making-computation-code-cancellable)
2020
* <a name='closing-resources-with-finally'></a>[Closing resources with `finally`](docs/cancellation-and-timeouts.md#closing-resources-with-finally)
2121
* <a name='run-non-cancellable-block'></a>[Run non-cancellable block](docs/cancellation-and-timeouts.md#run-non-cancellable-block)
2222
* <a name='timeout'></a>[Timeout](docs/cancellation-and-timeouts.md#timeout)
2323
<!--- TOC_REF docs/composing-suspending-functions.md -->
24-
* <a name='composing-suspending-functions'></a>[Composing suspending functions](docs/composing-suspending-functions.md#composing-suspending-functions)
24+
* <a name='composing-suspending-functions'></a>[Composing Suspending Functions](docs/composing-suspending-functions.md#composing-suspending-functions)
2525
* <a name='sequential-by-default'></a>[Sequential by default](docs/composing-suspending-functions.md#sequential-by-default)
2626
* <a name='concurrent-using-async'></a>[Concurrent using async](docs/composing-suspending-functions.md#concurrent-using-async)
2727
* <a name='lazily-started-async'></a>[Lazily started async](docs/composing-suspending-functions.md#lazily-started-async)
2828
* <a name='async-style-functions'></a>[Async-style functions](docs/composing-suspending-functions.md#async-style-functions)
2929
* <a name='structured-concurrency-with-async'></a>[Structured concurrency with async](docs/composing-suspending-functions.md#structured-concurrency-with-async)
3030
<!--- TOC_REF docs/coroutine-context-and-dispatchers.md -->
31-
* <a name='coroutine-context-and-dispatchers'></a>[Coroutine context and dispatchers](docs/coroutine-context-and-dispatchers.md#coroutine-context-and-dispatchers)
31+
* <a name='coroutine-context-and-dispatchers'></a>[Coroutine Context and Dispatchers](docs/coroutine-context-and-dispatchers.md#coroutine-context-and-dispatchers)
3232
* <a name='dispatchers-and-threads'></a>[Dispatchers and threads](docs/coroutine-context-and-dispatchers.md#dispatchers-and-threads)
3333
* <a name='unconfined-vs-confined-dispatcher'></a>[Unconfined vs confined dispatcher](docs/coroutine-context-and-dispatchers.md#unconfined-vs-confined-dispatcher)
3434
* <a name='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
4040
* <a name='combining-context-elements'></a>[Combining context elements](docs/coroutine-context-and-dispatchers.md#combining-context-elements)
4141
* <a name='coroutine-scope'></a>[Coroutine scope](docs/coroutine-context-and-dispatchers.md#coroutine-scope)
4242
* <a name='thread-local-data'></a>[Thread-local data](docs/coroutine-context-and-dispatchers.md#thread-local-data)
43-
<!--- TOC_REF docs/exception-handling.md -->
44-
* <a name='exception-handling'></a>[Exception handling](docs/exception-handling.md#exception-handling)
45-
* <a name='exception-propagation'></a>[Exception propagation](docs/exception-handling.md#exception-propagation)
46-
* <a name='coroutineexceptionhandler'></a>[CoroutineExceptionHandler](docs/exception-handling.md#coroutineexceptionhandler)
47-
* <a name='cancellation-and-exceptions'></a>[Cancellation and exceptions](docs/exception-handling.md#cancellation-and-exceptions)
48-
* <a name='exceptions-aggregation'></a>[Exceptions aggregation](docs/exception-handling.md#exceptions-aggregation)
49-
* <a name='supervision'></a>[Supervision](docs/exception-handling.md#supervision)
50-
* <a name='supervision-job'></a>[Supervision job](docs/exception-handling.md#supervision-job)
51-
* <a name='supervision-scope'></a>[Supervision scope](docs/exception-handling.md#supervision-scope)
52-
* <a name='exceptions-in-supervised-coroutines'></a>[Exceptions in supervised coroutines](docs/exception-handling.md#exceptions-in-supervised-coroutines)
43+
<!--- TOC_REF docs/flow.md -->
44+
* <a name='asynchronous-flow'></a>[Asynchronous Flow](docs/flow.md#asynchronous-flow)
45+
* <a name='representing-multiple-values'></a>[Representing multiple values](docs/flow.md#representing-multiple-values)
46+
* <a name='sequences'></a>[Sequences](docs/flow.md#sequences)
47+
* <a name='suspending-functions'></a>[Suspending functions](docs/flow.md#suspending-functions)
48+
* <a name='flows'></a>[Flows](docs/flow.md#flows)
49+
* <a name='flows-are-cold'></a>[Flows are cold](docs/flow.md#flows-are-cold)
50+
* <a name='flow-cancellation'></a>[Flow cancellation](docs/flow.md#flow-cancellation)
51+
* <a name='flow-builders'></a>[Flow builders](docs/flow.md#flow-builders)
52+
* <a name='intermediate-flow-operators'></a>[Intermediate flow operators](docs/flow.md#intermediate-flow-operators)
53+
* <a name='transform-operator'></a>[Transform operator](docs/flow.md#transform-operator)
54+
* <a name='size-limiting-operators'></a>[Size-limiting operators](docs/flow.md#size-limiting-operators)
55+
* <a name='terminal-flow-operators'></a>[Terminal flow operators](docs/flow.md#terminal-flow-operators)
56+
* <a name='flows-are-sequential'></a>[Flows are sequential](docs/flow.md#flows-are-sequential)
57+
* <a name='flow-context'></a>[Flow context](docs/flow.md#flow-context)
58+
* <a name='wrong-emission-withcontext'></a>[Wrong emission withContext](docs/flow.md#wrong-emission-withcontext)
59+
* <a name='flowon-operator'></a>[flowOn operator](docs/flow.md#flowon-operator)
60+
* <a name='buffering'></a>[Buffering](docs/flow.md#buffering)
61+
* <a name='conflation'></a>[Conflation](docs/flow.md#conflation)
62+
* <a name='processing-the-latest-value'></a>[Processing the latest value](docs/flow.md#processing-the-latest-value)
63+
* <a name='composing-multiple-flows'></a>[Composing multiple flows](docs/flow.md#composing-multiple-flows)
64+
* <a name='zip'></a>[Zip](docs/flow.md#zip)
65+
* <a name='combine'></a>[Combine](docs/flow.md#combine)
66+
* <a name='flattening-flows'></a>[Flattening flows](docs/flow.md#flattening-flows)
67+
* <a name='flatmapconcat'></a>[flatMapConcat](docs/flow.md#flatmapconcat)
68+
* <a name='flatmapmerge'></a>[flatMapMerge](docs/flow.md#flatmapmerge)
69+
* <a name='flatmaplatest'></a>[flatMapLatest](docs/flow.md#flatmaplatest)
70+
* <a name='flow-exceptions'></a>[Flow exceptions](docs/flow.md#flow-exceptions)
71+
* <a name='collector-try-and-catch'></a>[Collector try and catch](docs/flow.md#collector-try-and-catch)
72+
* <a name='everything-is-caught'></a>[Everything is caught](docs/flow.md#everything-is-caught)
73+
* <a name='exception-transparency'></a>[Exception transparency](docs/flow.md#exception-transparency)
74+
* <a name='transparent-catch'></a>[Transparent catch](docs/flow.md#transparent-catch)
75+
* <a name='catching-declaratively'></a>[Catching declaratively](docs/flow.md#catching-declaratively)
76+
* <a name='flow-completion'></a>[Flow completion](docs/flow.md#flow-completion)
77+
* <a name='imperative-finally-block'></a>[Imperative finally block](docs/flow.md#imperative-finally-block)
78+
* <a name='declarative-handling'></a>[Declarative handling](docs/flow.md#declarative-handling)
79+
* <a name='upstream-exceptions-only'></a>[Upstream exceptions only](docs/flow.md#upstream-exceptions-only)
80+
* <a name='imperative-versus-declarative'></a>[Imperative versus declarative](docs/flow.md#imperative-versus-declarative)
81+
* <a name='launching-flow'></a>[Launching flow](docs/flow.md#launching-flow)
5382
<!--- TOC_REF docs/channels.md -->
5483
* <a name='channels'></a>[Channels](docs/channels.md#channels)
5584
* <a name='channel-basics'></a>[Channel basics](docs/channels.md#channel-basics)
@@ -62,6 +91,16 @@ The main coroutines guide has moved to the [docs folder](docs/coroutines-guide.m
6291
* <a name='buffered-channels'></a>[Buffered channels](docs/channels.md#buffered-channels)
6392
* <a name='channels-are-fair'></a>[Channels are fair](docs/channels.md#channels-are-fair)
6493
* <a name='ticker-channels'></a>[Ticker channels](docs/channels.md#ticker-channels)
94+
<!--- TOC_REF docs/exception-handling.md -->
95+
* <a name='exception-handling'></a>[Exception Handling](docs/exception-handling.md#exception-handling)
96+
* <a name='exception-propagation'></a>[Exception propagation](docs/exception-handling.md#exception-propagation)
97+
* <a name='coroutineexceptionhandler'></a>[CoroutineExceptionHandler](docs/exception-handling.md#coroutineexceptionhandler)
98+
* <a name='cancellation-and-exceptions'></a>[Cancellation and exceptions](docs/exception-handling.md#cancellation-and-exceptions)
99+
* <a name='exceptions-aggregation'></a>[Exceptions aggregation](docs/exception-handling.md#exceptions-aggregation)
100+
* <a name='supervision'></a>[Supervision](docs/exception-handling.md#supervision)
101+
* <a name='supervision-job'></a>[Supervision job](docs/exception-handling.md#supervision-job)
102+
* <a name='supervision-scope'></a>[Supervision scope](docs/exception-handling.md#supervision-scope)
103+
* <a name='exceptions-in-supervised-coroutines'></a>[Exceptions in supervised coroutines](docs/exception-handling.md#exceptions-in-supervised-coroutines)
65104
<!--- TOC_REF docs/shared-mutable-state-and-concurrency.md -->
66105
* <a name='shared-mutable-state-and-concurrency'></a>[Shared mutable state and concurrency](docs/shared-mutable-state-and-concurrency.md#shared-mutable-state-and-concurrency)
67106
* <a name='the-problem'></a>[The problem](docs/shared-mutable-state-and-concurrency.md#the-problem)
@@ -72,7 +111,7 @@ The main coroutines guide has moved to the [docs folder](docs/coroutines-guide.m
72111
* <a name='mutual-exclusion'></a>[Mutual exclusion](docs/shared-mutable-state-and-concurrency.md#mutual-exclusion)
73112
* <a name='actors'></a>[Actors](docs/shared-mutable-state-and-concurrency.md#actors)
74113
<!--- TOC_REF docs/select-expression.md -->
75-
* <a name='select-expression-experimental'></a>[Select expression (experimental)](docs/select-expression.md#select-expression-experimental)
114+
* <a name='select-expression-experimental'></a>[Select Expression (experimental)](docs/select-expression.md#select-expression-experimental)
76115
* <a name='selecting-from-channels'></a>[Selecting from channels](docs/select-expression.md#selecting-from-channels)
77116
* <a name='selecting-on-close'></a>[Selecting on close](docs/select-expression.md#selecting-on-close)
78117
* <a name='selecting-to-send'></a>[Selecting to send](docs/select-expression.md#selecting-to-send)

docs/_nav.yml

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@
77
- md: cancellation-and-timeouts.md
88
url: cancellation-and-timeouts.html
99
title: Cancellation and Timeouts
10-
- md: channels.md
11-
url: channels.html
12-
title: Channels
1310
- md: composing-suspending-functions.md
1411
url: composing-suspending-functions.html
1512
title: Composing Suspending Functions
1613
- md: coroutine-context-and-dispatchers.md
1714
url: coroutine-context-and-dispatchers.html
1815
title: Coroutine Context and Dispatchers
16+
- md: flow.md
17+
url: flow.html
18+
title: Asynchronous Flow
19+
- md: channels.md
20+
url: channels.html
21+
title: Channels
1922
- md: exception-handling.md
2023
url: exception-handling.html
21-
title: Exception Handling
22-
- md: select-expression.md
23-
url: select-expression.html
24-
title: Select Expression
24+
title: Exception Handling and Supervision
2525
- md: shared-mutable-state-and-concurrency.md
2626
url: shared-mutable-state-and-concurrency.html
2727
title: Shared Mutable State and Concurrency
28+
- md: select-expression.md
29+
url: select-expression.html
30+
title: Select Expression (experimental)

docs/basics.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BasicsGuideTest {
2020

2121
<!--- TOC -->
2222

23-
* [Coroutine basics](#coroutine-basics)
23+
* [Coroutine Basics](#coroutine-basics)
2424
* [Your first coroutine](#your-first-coroutine)
2525
* [Bridging blocking and non-blocking worlds](#bridging-blocking-and-non-blocking-worlds)
2626
* [Waiting for a job](#waiting-for-a-job)
@@ -33,7 +33,7 @@ class BasicsGuideTest {
3333
<!--- END_TOC -->
3434

3535

36-
## Coroutine basics
36+
## Coroutine Basics
3737

3838
This section covers basic coroutine concepts.
3939

docs/cancellation-and-timeouts.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CancellationTimeOutsGuideTest {
1919

2020
<!--- TOC -->
2121

22-
* [Cancellation and timeouts](#cancellation-and-timeouts)
22+
* [Cancellation and Timeouts](#cancellation-and-timeouts)
2323
* [Cancelling coroutine execution](#cancelling-coroutine-execution)
2424
* [Cancellation is cooperative](#cancellation-is-cooperative)
2525
* [Making computation code cancellable](#making-computation-code-cancellable)
@@ -29,7 +29,7 @@ class CancellationTimeOutsGuideTest {
2929

3030
<!--- END_TOC -->
3131

32-
## Cancellation and timeouts
32+
## Cancellation and Timeouts
3333

3434
This section covers coroutine cancellation and timeouts.
3535

docs/composing-suspending-functions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ComposingGuideTest {
2020

2121
<!--- TOC -->
2222

23-
* [Composing suspending functions](#composing-suspending-functions)
23+
* [Composing Suspending Functions](#composing-suspending-functions)
2424
* [Sequential by default](#sequential-by-default)
2525
* [Concurrent using async](#concurrent-using-async)
2626
* [Lazily started async](#lazily-started-async)
@@ -29,7 +29,7 @@ class ComposingGuideTest {
2929

3030
<!--- END_TOC -->
3131

32-
## Composing suspending functions
32+
## Composing Suspending Functions
3333

3434
This section covers various approaches to composition of suspending functions.
3535

docs/coroutine-context-and-dispatchers.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DispatchersGuideTest {
2020

2121
<!--- TOC -->
2222

23-
* [Coroutine context and dispatchers](#coroutine-context-and-dispatchers)
23+
* [Coroutine Context and Dispatchers](#coroutine-context-and-dispatchers)
2424
* [Dispatchers and threads](#dispatchers-and-threads)
2525
* [Unconfined vs confined dispatcher](#unconfined-vs-confined-dispatcher)
2626
* [Debugging coroutines and threads](#debugging-coroutines-and-threads)
@@ -35,7 +35,7 @@ class DispatchersGuideTest {
3535

3636
<!--- END_TOC -->
3737

38-
## Coroutine context and dispatchers
38+
## Coroutine Context and Dispatchers
3939

4040
Coroutines always execute in some context represented by a value of the
4141
[CoroutineContext](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/-coroutine-context/)

docs/coroutines-guide.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ In order to use coroutines as well as follow the examples in this guide, you nee
1515

1616
## Table of contents
1717

18-
* [Coroutine basics](basics.md)
19-
* [Cancellation and timeouts](cancellation-and-timeouts.md)
20-
* [Composing suspending functions](composing-suspending-functions.md)
21-
* [Coroutine context and dispatchers](coroutine-context-and-dispatchers.md)
22-
* [Exception handling and supervision](exception-handling.md)
23-
* [Channels (experimental)](channels.md)
24-
* [Shared mutable state and concurrency](shared-mutable-state-and-concurrency.md)
25-
* [Select expression (experimental)](select-expression.md)
18+
* [Basics](basics.md)
19+
* [Cancellation and Timeouts](cancellation-and-timeouts.md)
20+
* [Composing Suspending Functions](composing-suspending-functions.md)
21+
* [Coroutine Context and Dispatchers](coroutine-context-and-dispatchers.md)
22+
* [Asynchronous Flow](flow.md)
23+
* [Channels](channels.md)
24+
* [Exception Handling and Supervision](exception-handling.md)
25+
* [Shared Mutable State and Concurrency](shared-mutable-state-and-concurrency.md)
26+
* [Select Expression (experimental)](select-expression.md)
2627

2728
## Additional references
2829

docs/exception-handling.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ class ExceptionsGuideTest {
1919

2020
<!--- TOC -->
2121

22-
* [Exception handling](#exception-handling)
22+
* [Exception Handling](#exception-handling)
2323
* [Exception propagation](#exception-propagation)
2424
* [CoroutineExceptionHandler](#coroutineexceptionhandler)
2525
* [Cancellation and exceptions](#cancellation-and-exceptions)
2626
* [Exceptions aggregation](#exceptions-aggregation)
27-
* [Supervision](#supervision)
28-
* [Supervision job](#supervision-job)
29-
* [Supervision scope](#supervision-scope)
30-
* [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)
3131

3232
<!--- END_TOC -->
3333

34-
## Exception handling
34+
## Exception Handling
3535

3636

3737
This section covers exception handling and cancellation on exceptions.
@@ -355,7 +355,7 @@ Caught original java.io.IOException
355355
```
356356
<!--- TEST-->
357357

358-
## Supervision
358+
### Supervision
359359

360360
As we have studied before, cancellation is a bidirectional relationship propagating through the whole
361361
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
367367
Another example is a server process that spawns several children jobs and needs to _supervise_
368368
their execution, tracking their failures and restarting just those children jobs that had failed.
369369

370-
### Supervision job
370+
#### Supervision job
371371

372372
For these purposes [SupervisorJob][SupervisorJob()] can be used. It is similar to a regular [Job][Job()] with the only exception that cancellation is propagated
373373
only downwards. It is easy to demonstrate with an example:
@@ -421,7 +421,7 @@ Second child is cancelled because supervisor is cancelled
421421
<!--- TEST-->
422422

423423

424-
### Supervision scope
424+
#### Supervision scope
425425

426426
For *scoped* concurrency [supervisorScope] can be used instead of [coroutineScope] for the same purpose. It propagates cancellation
427427
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
469469
```
470470
<!--- TEST-->
471471

472-
### Exceptions in supervised coroutines
472+
#### Exceptions in supervised coroutines
473473

474474
Another crucial difference between regular and supervisor jobs is exception handling.
475475
Every child should handle its exceptions by itself via exception handling mechanisms.

0 commit comments

Comments
 (0)