Merge remote-tracking branch 'origin/master' into develop
diff --git a/docs/flow.md b/docs/flow.md
index eef33a4..143f9e9 100644
--- a/docs/flow.md
+++ b/docs/flow.md
@@ -56,16 +56,16 @@
### Representing multiple values
Multiple values can be represented in Kotlin using [collections].
-For example, we can have a function `foo()` that returns a [List]
+For example, we can have a `simple` function that returns a [List]
of three numbers and then print them all using [forEach]:
<div class="sample" markdown="1" theme="idea" data-min-compiler-version="1.3">
```kotlin
-fun foo(): List<Int> = listOf(1, 2, 3)
+fun simple(): List<Int> = listOf(1, 2, 3)
fun main() {
- foo().forEach { value -> println(value) }
+ simple().forEach { value -> println(value) }
}
```
@@ -91,7 +91,7 @@
<div class="sample" markdown="1" theme="idea" data-min-compiler-version="1.3">
```kotlin
-fun foo(): Sequence<Int> = sequence { // sequence builder
+fun simple(): Sequence<Int> = sequence { // sequence builder
for (i in 1..3) {
Thread.sleep(100) // pretend we are computing it
yield(i) // yield next value
@@ -99,7 +99,7 @@
}
fun main() {
- foo().forEach { value -> println(value) }
+ simple().forEach { value -> println(value) }
}
```
@@ -118,7 +118,7 @@
#### Suspending functions
However, this computation blocks the main thread that is running the code.
-When these values are computed by asynchronous code we can mark the function `foo` with a `suspend` modifier,
+When these values are computed by asynchronous code we can mark the `simple` function with a `suspend` modifier,
so that it can perform its work without blocking and return the result as a list:
<div class="sample" markdown="1" theme="idea" data-min-compiler-version="1.3">
@@ -127,13 +127,13 @@
import kotlinx.coroutines.*
//sampleStart
-suspend fun foo(): List<Int> {
+suspend fun simple(): List<Int> {
delay(1000) // pretend we are doing something asynchronous here
return listOf(1, 2, 3)
}
fun main() = runBlocking<Unit> {
- foo().forEach { value -> println(value) }
+ simple().forEach { value -> println(value) }
}
//sampleEnd
```
@@ -162,7 +162,7 @@
import kotlinx.coroutines.flow.*
//sampleStart
-fun foo(): Flow<Int> = flow { // flow builder
+fun simple(): Flow<Int> = flow { // flow builder
for (i in 1..3) {
delay(100) // pretend we are doing something useful here
emit(i) // emit next value
@@ -178,7 +178,7 @@
}
}
// Collect the flow
- foo().collect { value -> println(value) }
+ simple().collect { value -> println(value) }
}
//sampleEnd
```
@@ -205,11 +205,11 @@
* A builder function for [Flow] type is called [flow].
* Code inside the `flow { ... }` builder block can suspend.
-* The function `foo()` is no longer marked with `suspend` modifier.
+* The `simple` function is no longer marked with `suspend` modifier.
* Values are _emitted_ from the flow using [emit][FlowCollector.emit] function.
* Values are _collected_ from the flow using [collect][collect] function.
-> We can replace [delay] with `Thread.sleep` in the body of `foo`'s `flow { ... }` and see that the main
+> We can replace [delay] with `Thread.sleep` in the body of `simple`'s `flow { ... }` and see that the main
thread is blocked in this case.
### Flows are cold
@@ -224,7 +224,7 @@
import kotlinx.coroutines.flow.*
//sampleStart
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
println("Flow started")
for (i in 1..3) {
delay(100)
@@ -233,8 +233,8 @@
}
fun main() = runBlocking<Unit> {
- println("Calling foo...")
- val flow = foo()
+ println("Calling simple function...")
+ val flow = simple()
println("Calling collect...")
flow.collect { value -> println(value) }
println("Calling collect again...")
@@ -250,7 +250,7 @@
Which prints:
```text
-Calling foo...
+Calling simple function...
Calling collect...
Flow started
1
@@ -265,8 +265,8 @@
<!--- TEST -->
-This is a key reason the `foo()` function (which returns a flow) is not marked with `suspend` modifier.
-By itself, `foo()` returns quickly and does not wait for anything. The flow starts every time it is collected,
+This is a key reason the `simple` function (which returns a flow) is not marked with `suspend` modifier.
+By itself, `simple()` call returns quickly and does not wait for anything. The flow starts every time it is collected,
that is why we see "Flow started" when we call `collect` again.
### Flow cancellation basics
@@ -283,7 +283,7 @@
import kotlinx.coroutines.flow.*
//sampleStart
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
delay(100)
println("Emitting $i")
@@ -293,7 +293,7 @@
fun main() = runBlocking<Unit> {
withTimeoutOrNull(250) { // Timeout after 250ms
- foo().collect { value -> println(value) }
+ simple().collect { value -> println(value) }
}
println("Done")
}
@@ -304,7 +304,7 @@
> You can get the full code from [here](../kotlinx-coroutines-core/jvm/test/guide/example-flow-06.kt).
-Notice how only two numbers get emitted by the flow in `foo()` function, producing the following output:
+Notice how only two numbers get emitted by the flow in the `simple` function, producing the following output:
```text
Emitting 1
@@ -592,14 +592,14 @@
### Flow context
Collection of a flow always happens in the context of the calling coroutine. For example, if there is
-a `foo` flow, then the following code runs in the context specified
-by the author of this code, regardless of the implementation details of the `foo` flow:
+a `simple` flow, then the following code runs in the context specified
+by the author of this code, regardless of the implementation details of the `simple` flow:
<div class="sample" markdown="1" theme="idea" data-highlight-only>
```kotlin
withContext(context) {
- foo.collect { value ->
+ simple().collect { value ->
println(value) // run in the specified context
}
}
@@ -612,7 +612,7 @@
This property of a flow is called _context preservation_.
So, by default, code in the `flow { ... }` builder runs in the context that is provided by a collector
-of the corresponding flow. For example, consider the implementation of `foo` that prints the thread
+of the corresponding flow. For example, consider the implementation of a `simple` function that prints the thread
it is called on and emits three numbers:
<div class="sample" markdown="1" theme="idea" data-min-compiler-version="1.3">
@@ -624,15 +624,15 @@
fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
//sampleStart
-fun foo(): Flow<Int> = flow {
- log("Started foo flow")
+fun simple(): Flow<Int> = flow {
+ log("Started simple flow")
for (i in 1..3) {
emit(i)
}
}
fun main() = runBlocking<Unit> {
- foo().collect { value -> log("Collected $value") }
+ simple().collect { value -> log("Collected $value") }
}
//sampleEnd
```
@@ -644,7 +644,7 @@
Running this code produces:
```text
-[main @coroutine#1] Started foo flow
+[main @coroutine#1] Started simple flow
[main @coroutine#1] Collected 1
[main @coroutine#1] Collected 2
[main @coroutine#1] Collected 3
@@ -652,7 +652,7 @@
<!--- TEST FLEXIBLE_THREAD -->
-Since `foo().collect` is called from the main thread, the body of `foo`'s flow is also called in the main thread.
+Since `simple().collect` is called from the main thread, the body of `simple`'s flow is also called in the main thread.
This is the perfect default for fast-running or asynchronous code that does not care about the execution context and
does not block the caller.
@@ -672,7 +672,7 @@
import kotlinx.coroutines.flow.*
//sampleStart
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
// The WRONG way to change context for CPU-consuming code in flow builder
kotlinx.coroutines.withContext(Dispatchers.Default) {
for (i in 1..3) {
@@ -683,7 +683,7 @@
}
fun main() = runBlocking<Unit> {
- foo().collect { value -> println(value) }
+ simple().collect { value -> println(value) }
}
//sampleEnd
```
@@ -719,7 +719,7 @@
fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
//sampleStart
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
Thread.sleep(100) // pretend we are computing it in CPU-consuming way
log("Emitting $i")
@@ -728,7 +728,7 @@
}.flowOn(Dispatchers.Default) // RIGHT way to change context for CPU-consuming code in flow builder
fun main() = runBlocking<Unit> {
- foo().collect { value ->
+ simple().collect { value ->
log("Collected $value")
}
}
@@ -759,7 +759,7 @@
Running different parts of a flow in different coroutines can be helpful from the standpoint of the overall time it takes
to collect the flow, especially when long-running asynchronous operations are involved. For example, consider a case when
-the emission by `foo()` flow is slow, taking 100 ms to produce an element; and collector is also slow,
+the emission by a `simple` flow is slow, taking 100 ms to produce an element; and collector is also slow,
taking 300 ms to process an element. Let's see how long it takes to collect such a flow with three numbers:
<div class="sample" markdown="1" theme="idea" data-min-compiler-version="1.3">
@@ -770,7 +770,7 @@
import kotlin.system.*
//sampleStart
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
delay(100) // pretend we are asynchronously waiting 100 ms
emit(i) // emit next value
@@ -779,7 +779,7 @@
fun main() = runBlocking<Unit> {
val time = measureTimeMillis {
- foo().collect { value ->
+ simple().collect { value ->
delay(300) // pretend we are processing it for 300 ms
println(value)
}
@@ -804,7 +804,7 @@
<!--- TEST ARBITRARY_TIME -->
-We can use a [buffer] operator on a flow to run emitting code of `foo()` concurrently with collecting code,
+We can use a [buffer] operator on a flow to run emitting code of the `simple` flow concurrently with collecting code,
as opposed to running them sequentially:
<div class="sample" markdown="1" theme="idea" data-min-compiler-version="1.3">
@@ -814,7 +814,7 @@
import kotlinx.coroutines.flow.*
import kotlin.system.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
delay(100) // pretend we are asynchronously waiting 100 ms
emit(i) // emit next value
@@ -824,7 +824,7 @@
fun main() = runBlocking<Unit> {
//sampleStart
val time = measureTimeMillis {
- foo()
+ simple()
.buffer() // buffer emissions, don't wait
.collect { value ->
delay(300) // pretend we are processing it for 300 ms
@@ -869,7 +869,7 @@
import kotlinx.coroutines.flow.*
import kotlin.system.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
delay(100) // pretend we are asynchronously waiting 100 ms
emit(i) // emit next value
@@ -879,7 +879,7 @@
fun main() = runBlocking<Unit> {
//sampleStart
val time = measureTimeMillis {
- foo()
+ simple()
.conflate() // conflate emissions, don't process each one
.collect { value ->
delay(300) // pretend we are processing it for 300 ms
@@ -920,7 +920,7 @@
import kotlinx.coroutines.flow.*
import kotlin.system.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
delay(100) // pretend we are asynchronously waiting 100 ms
emit(i) // emit next value
@@ -930,7 +930,7 @@
fun main() = runBlocking<Unit> {
//sampleStart
val time = measureTimeMillis {
- foo()
+ simple()
.collectLatest { value -> // cancel & restart on the latest value
println("Collecting $value")
delay(300) // pretend we are processing it for 300 ms
@@ -1281,7 +1281,7 @@
import kotlinx.coroutines.flow.*
//sampleStart
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
println("Emitting $i")
emit(i) // emit next value
@@ -1290,7 +1290,7 @@
fun main() = runBlocking<Unit> {
try {
- foo().collect { value ->
+ simple().collect { value ->
println(value)
check(value <= 1) { "Collected $value" }
}
@@ -1331,7 +1331,7 @@
import kotlinx.coroutines.flow.*
//sampleStart
-fun foo(): Flow<String> =
+fun simple(): Flow<String> =
flow {
for (i in 1..3) {
println("Emitting $i")
@@ -1345,7 +1345,7 @@
fun main() = runBlocking<Unit> {
try {
- foo().collect { value -> println(value) }
+ simple().collect { value -> println(value) }
} catch (e: Throwable) {
println("Caught $e")
}
@@ -1392,7 +1392,7 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<String> =
+fun simple(): Flow<String> =
flow {
for (i in 1..3) {
println("Emitting $i")
@@ -1406,7 +1406,7 @@
fun main() = runBlocking<Unit> {
//sampleStart
- foo()
+ simple()
.catch { e -> emit("Caught $e") } // emit on exception
.collect { value -> println(value) }
//sampleEnd
@@ -1439,7 +1439,7 @@
import kotlinx.coroutines.flow.*
//sampleStart
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
println("Emitting $i")
emit(i)
@@ -1447,7 +1447,7 @@
}
fun main() = runBlocking<Unit> {
- foo()
+ simple()
.catch { e -> println("Caught $e") } // does not catch downstream exceptions
.collect { value ->
check(value <= 1) { "Collected $value" }
@@ -1483,7 +1483,7 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
println("Emitting $i")
emit(i)
@@ -1492,7 +1492,7 @@
fun main() = runBlocking<Unit> {
//sampleStart
- foo()
+ simple()
.onEach { value ->
check(value <= 1) { "Collected $value" }
println(value)
@@ -1534,11 +1534,11 @@
import kotlinx.coroutines.flow.*
//sampleStart
-fun foo(): Flow<Int> = (1..3).asFlow()
+fun simple(): Flow<Int> = (1..3).asFlow()
fun main() = runBlocking<Unit> {
try {
- foo().collect { value -> println(value) }
+ simple().collect { value -> println(value) }
} finally {
println("Done")
}
@@ -1550,7 +1550,7 @@
> You can get the full code from [here](../kotlinx-coroutines-core/jvm/test/guide/example-flow-31.kt).
-This code prints three numbers produced by the `foo()` flow followed by a "Done" string:
+This code prints three numbers produced by the `simple` flow followed by a "Done" string:
```text
1
@@ -1574,11 +1574,11 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<Int> = (1..3).asFlow()
+fun simple(): Flow<Int> = (1..3).asFlow()
fun main() = runBlocking<Unit> {
//sampleStart
- foo()
+ simple()
.onCompletion { println("Done") }
.collect { value -> println(value) }
//sampleEnd
@@ -1597,7 +1597,7 @@
The key advantage of [onCompletion] is a nullable `Throwable` parameter of the lambda that can be used
to determine whether the flow collection was completed normally or exceptionally. In the following
-example the `foo()` flow throws an exception after emitting the number 1:
+example the `simple` flow throws an exception after emitting the number 1:
<div class="sample" markdown="1" theme="idea" data-min-compiler-version="1.3">
@@ -1606,13 +1606,13 @@
import kotlinx.coroutines.flow.*
//sampleStart
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
emit(1)
throw RuntimeException()
}
fun main() = runBlocking<Unit> {
- foo()
+ simple()
.onCompletion { cause -> if (cause != null) println("Flow completed exceptionally") }
.catch { cause -> println("Caught exception") }
.collect { value -> println(value) }
@@ -1649,10 +1649,10 @@
import kotlinx.coroutines.flow.*
//sampleStart
-fun foo(): Flow<Int> = (1..3).asFlow()
+fun simple(): Flow<Int> = (1..3).asFlow()
fun main() = runBlocking<Unit> {
- foo()
+ simple()
.onCompletion { cause -> println("Flow completed with $cause") }
.collect { value ->
check(value <= 1) { "Collected $value" }
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-01.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-01.kt
index df14603..7c6c157 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-01.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-01.kt
@@ -5,8 +5,8 @@
// This file was automatically generated from flow.md by Knit tool. Do not edit.
package kotlinx.coroutines.guide.exampleFlow01
-fun foo(): List<Int> = listOf(1, 2, 3)
+fun simple(): List<Int> = listOf(1, 2, 3)
fun main() {
- foo().forEach { value -> println(value) }
+ simple().forEach { value -> println(value) }
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-02.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-02.kt
index fcb61b9..e3fabe3 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-02.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-02.kt
@@ -5,7 +5,7 @@
// This file was automatically generated from flow.md by Knit tool. Do not edit.
package kotlinx.coroutines.guide.exampleFlow02
-fun foo(): Sequence<Int> = sequence { // sequence builder
+fun simple(): Sequence<Int> = sequence { // sequence builder
for (i in 1..3) {
Thread.sleep(100) // pretend we are computing it
yield(i) // yield next value
@@ -13,5 +13,5 @@
}
fun main() {
- foo().forEach { value -> println(value) }
+ simple().forEach { value -> println(value) }
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-03.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-03.kt
index ba94b2f..61601dd 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-03.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-03.kt
@@ -7,11 +7,11 @@
import kotlinx.coroutines.*
-suspend fun foo(): List<Int> {
+suspend fun simple(): List<Int> {
delay(1000) // pretend we are doing something asynchronous here
return listOf(1, 2, 3)
}
fun main() = runBlocking<Unit> {
- foo().forEach { value -> println(value) }
+ simple().forEach { value -> println(value) }
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-04.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-04.kt
index 3e3aea0..c91f704 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-04.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-04.kt
@@ -8,7 +8,7 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<Int> = flow { // flow builder
+fun simple(): Flow<Int> = flow { // flow builder
for (i in 1..3) {
delay(100) // pretend we are doing something useful here
emit(i) // emit next value
@@ -24,5 +24,5 @@
}
}
// Collect the flow
- foo().collect { value -> println(value) }
+ simple().collect { value -> println(value) }
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-05.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-05.kt
index 6d0e451..788d941 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-05.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-05.kt
@@ -8,7 +8,7 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
println("Flow started")
for (i in 1..3) {
delay(100)
@@ -17,8 +17,8 @@
}
fun main() = runBlocking<Unit> {
- println("Calling foo...")
- val flow = foo()
+ println("Calling simple function...")
+ val flow = simple()
println("Calling collect...")
flow.collect { value -> println(value) }
println("Calling collect again...")
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-06.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-06.kt
index 9d9348e..bd4058e 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-06.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-06.kt
@@ -8,7 +8,7 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
delay(100)
println("Emitting $i")
@@ -18,7 +18,7 @@
fun main() = runBlocking<Unit> {
withTimeoutOrNull(250) { // Timeout after 250ms
- foo().collect { value -> println(value) }
+ simple().collect { value -> println(value) }
}
println("Done")
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-13.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-13.kt
index 4feacc6..945ce89 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-13.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-13.kt
@@ -10,13 +10,13 @@
fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
-fun foo(): Flow<Int> = flow {
- log("Started foo flow")
+fun simple(): Flow<Int> = flow {
+ log("Started simple flow")
for (i in 1..3) {
emit(i)
}
}
fun main() = runBlocking<Unit> {
- foo().collect { value -> log("Collected $value") }
+ simple().collect { value -> log("Collected $value") }
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-14.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-14.kt
index c0f2320..b5fc35e 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-14.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-14.kt
@@ -8,7 +8,7 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
// The WRONG way to change context for CPU-consuming code in flow builder
kotlinx.coroutines.withContext(Dispatchers.Default) {
for (i in 1..3) {
@@ -19,5 +19,5 @@
}
fun main() = runBlocking<Unit> {
- foo().collect { value -> println(value) }
+ simple().collect { value -> println(value) }
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-15.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-15.kt
index 8f0e395..0218e99 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-15.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-15.kt
@@ -10,7 +10,7 @@
fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
Thread.sleep(100) // pretend we are computing it in CPU-consuming way
log("Emitting $i")
@@ -19,7 +19,7 @@
}.flowOn(Dispatchers.Default) // RIGHT way to change context for CPU-consuming code in flow builder
fun main() = runBlocking<Unit> {
- foo().collect { value ->
+ simple().collect { value ->
log("Collected $value")
}
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-16.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-16.kt
index d2f41ff..7f3414f 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-16.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-16.kt
@@ -9,7 +9,7 @@
import kotlinx.coroutines.flow.*
import kotlin.system.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
delay(100) // pretend we are asynchronously waiting 100 ms
emit(i) // emit next value
@@ -18,7 +18,7 @@
fun main() = runBlocking<Unit> {
val time = measureTimeMillis {
- foo().collect { value ->
+ simple().collect { value ->
delay(300) // pretend we are processing it for 300 ms
println(value)
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-17.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-17.kt
index 5db79df..ed71617 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-17.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-17.kt
@@ -9,7 +9,7 @@
import kotlinx.coroutines.flow.*
import kotlin.system.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
delay(100) // pretend we are asynchronously waiting 100 ms
emit(i) // emit next value
@@ -18,7 +18,7 @@
fun main() = runBlocking<Unit> {
val time = measureTimeMillis {
- foo()
+ simple()
.buffer() // buffer emissions, don't wait
.collect { value ->
delay(300) // pretend we are processing it for 300 ms
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-18.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-18.kt
index 3c1a8a1..fc7bdef 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-18.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-18.kt
@@ -9,7 +9,7 @@
import kotlinx.coroutines.flow.*
import kotlin.system.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
delay(100) // pretend we are asynchronously waiting 100 ms
emit(i) // emit next value
@@ -18,7 +18,7 @@
fun main() = runBlocking<Unit> {
val time = measureTimeMillis {
- foo()
+ simple()
.conflate() // conflate emissions, don't process each one
.collect { value ->
delay(300) // pretend we are processing it for 300 ms
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-19.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-19.kt
index 1725276..f4ee219 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-19.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-19.kt
@@ -9,7 +9,7 @@
import kotlinx.coroutines.flow.*
import kotlin.system.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
delay(100) // pretend we are asynchronously waiting 100 ms
emit(i) // emit next value
@@ -18,7 +18,7 @@
fun main() = runBlocking<Unit> {
val time = measureTimeMillis {
- foo()
+ simple()
.collectLatest { value -> // cancel & restart on the latest value
println("Collecting $value")
delay(300) // pretend we are processing it for 300 ms
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-26.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-26.kt
index e489c3f..95f9a11 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-26.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-26.kt
@@ -8,7 +8,7 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
println("Emitting $i")
emit(i) // emit next value
@@ -17,7 +17,7 @@
fun main() = runBlocking<Unit> {
try {
- foo().collect { value ->
+ simple().collect { value ->
println(value)
check(value <= 1) { "Collected $value" }
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-27.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-27.kt
index f9ef979..3f34a76 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-27.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-27.kt
@@ -8,7 +8,7 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<String> =
+fun simple(): Flow<String> =
flow {
for (i in 1..3) {
println("Emitting $i")
@@ -22,7 +22,7 @@
fun main() = runBlocking<Unit> {
try {
- foo().collect { value -> println(value) }
+ simple().collect { value -> println(value) }
} catch (e: Throwable) {
println("Caught $e")
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-28.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-28.kt
index 84fc69f..02b231e 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-28.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-28.kt
@@ -8,7 +8,7 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<String> =
+fun simple(): Flow<String> =
flow {
for (i in 1..3) {
println("Emitting $i")
@@ -21,7 +21,7 @@
}
fun main() = runBlocking<Unit> {
- foo()
+ simple()
.catch { e -> emit("Caught $e") } // emit on exception
.collect { value -> println(value) }
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-29.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-29.kt
index 6c60c5d..5ec37af 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-29.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-29.kt
@@ -8,7 +8,7 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
println("Emitting $i")
emit(i)
@@ -16,7 +16,7 @@
}
fun main() = runBlocking<Unit> {
- foo()
+ simple()
.catch { e -> println("Caught $e") } // does not catch downstream exceptions
.collect { value ->
check(value <= 1) { "Collected $value" }
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-30.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-30.kt
index e21c77f..e787ca3 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-30.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-30.kt
@@ -8,7 +8,7 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
for (i in 1..3) {
println("Emitting $i")
emit(i)
@@ -16,7 +16,7 @@
}
fun main() = runBlocking<Unit> {
- foo()
+ simple()
.onEach { value ->
check(value <= 1) { "Collected $value" }
println(value)
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-31.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-31.kt
index 9b2855e..19fcb1c 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-31.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-31.kt
@@ -8,11 +8,11 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<Int> = (1..3).asFlow()
+fun simple(): Flow<Int> = (1..3).asFlow()
fun main() = runBlocking<Unit> {
try {
- foo().collect { value -> println(value) }
+ simple().collect { value -> println(value) }
} finally {
println("Done")
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-32.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-32.kt
index 3ad74ae..9848957 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-32.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-32.kt
@@ -8,10 +8,10 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<Int> = (1..3).asFlow()
+fun simple(): Flow<Int> = (1..3).asFlow()
fun main() = runBlocking<Unit> {
- foo()
+ simple()
.onCompletion { println("Done") }
.collect { value -> println(value) }
}
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-33.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-33.kt
index c0e0ab3..9f86765 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-33.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-33.kt
@@ -8,13 +8,13 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<Int> = flow {
+fun simple(): Flow<Int> = flow {
emit(1)
throw RuntimeException()
}
fun main() = runBlocking<Unit> {
- foo()
+ simple()
.onCompletion { cause -> if (cause != null) println("Flow completed exceptionally") }
.catch { cause -> println("Caught exception") }
.collect { value -> println(value) }
diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-flow-34.kt b/kotlinx-coroutines-core/jvm/test/guide/example-flow-34.kt
index 4b79a73..b2cee7f 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/example-flow-34.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/example-flow-34.kt
@@ -8,10 +8,10 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-fun foo(): Flow<Int> = (1..3).asFlow()
+fun simple(): Flow<Int> = (1..3).asFlow()
fun main() = runBlocking<Unit> {
- foo()
+ simple()
.onCompletion { cause -> println("Flow completed with $cause") }
.collect { value ->
check(value <= 1) { "Collected $value" }
diff --git a/kotlinx-coroutines-core/jvm/test/guide/test/FlowGuideTest.kt b/kotlinx-coroutines-core/jvm/test/guide/test/FlowGuideTest.kt
index 1d7f952..7fa9cc8 100644
--- a/kotlinx-coroutines-core/jvm/test/guide/test/FlowGuideTest.kt
+++ b/kotlinx-coroutines-core/jvm/test/guide/test/FlowGuideTest.kt
@@ -50,7 +50,7 @@
@Test
fun testExampleFlow05() {
test("ExampleFlow05") { kotlinx.coroutines.guide.exampleFlow05.main() }.verifyLines(
- "Calling foo...",
+ "Calling simple function...",
"Calling collect...",
"Flow started",
"1",
@@ -139,7 +139,7 @@
@Test
fun testExampleFlow13() {
test("ExampleFlow13") { kotlinx.coroutines.guide.exampleFlow13.main() }.verifyLinesFlexibleThread(
- "[main @coroutine#1] Started foo flow",
+ "[main @coroutine#1] Started simple flow",
"[main @coroutine#1] Collected 1",
"[main @coroutine#1] Collected 2",
"[main @coroutine#1] Collected 3"