Skip to content

Commit 64571aa

Browse files
committed
Merge remote-tracking branch 'origin/master' into develop
2 parents d718970 + ccdc563 commit 64571aa

24 files changed

+112
-112
lines changed

docs/flow.md

+64-64
Large diffs are not rendered by default.

kotlinx-coroutines-core/jvm/test/guide/example-flow-01.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// This file was automatically generated from flow.md by Knit tool. Do not edit.
66
package kotlinx.coroutines.guide.exampleFlow01
77

8-
fun foo(): List<Int> = listOf(1, 2, 3)
8+
fun simple(): List<Int> = listOf(1, 2, 3)
99

1010
fun main() {
11-
foo().forEach { value -> println(value) }
11+
simple().forEach { value -> println(value) }
1212
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-02.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
// This file was automatically generated from flow.md by Knit tool. Do not edit.
66
package kotlinx.coroutines.guide.exampleFlow02
77

8-
fun foo(): Sequence<Int> = sequence { // sequence builder
8+
fun simple(): Sequence<Int> = sequence { // sequence builder
99
for (i in 1..3) {
1010
Thread.sleep(100) // pretend we are computing it
1111
yield(i) // yield next value
1212
}
1313
}
1414

1515
fun main() {
16-
foo().forEach { value -> println(value) }
16+
simple().forEach { value -> println(value) }
1717
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-03.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ package kotlinx.coroutines.guide.exampleFlow03
77

88
import kotlinx.coroutines.*
99

10-
suspend fun foo(): List<Int> {
10+
suspend fun simple(): List<Int> {
1111
delay(1000) // pretend we are doing something asynchronous here
1212
return listOf(1, 2, 3)
1313
}
1414

1515
fun main() = runBlocking<Unit> {
16-
foo().forEach { value -> println(value) }
16+
simple().forEach { value -> println(value) }
1717
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-04.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow04
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010

11-
fun foo(): Flow<Int> = flow { // flow builder
11+
fun simple(): Flow<Int> = flow { // flow builder
1212
for (i in 1..3) {
1313
delay(100) // pretend we are doing something useful here
1414
emit(i) // emit next value
@@ -24,5 +24,5 @@ fun main() = runBlocking<Unit> {
2424
}
2525
}
2626
// Collect the flow
27-
foo().collect { value -> println(value) }
27+
simple().collect { value -> println(value) }
2828
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-05.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow05
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010

11-
fun foo(): Flow<Int> = flow {
11+
fun simple(): Flow<Int> = flow {
1212
println("Flow started")
1313
for (i in 1..3) {
1414
delay(100)
@@ -17,8 +17,8 @@ fun foo(): Flow<Int> = flow {
1717
}
1818

1919
fun main() = runBlocking<Unit> {
20-
println("Calling foo...")
21-
val flow = foo()
20+
println("Calling simple function...")
21+
val flow = simple()
2222
println("Calling collect...")
2323
flow.collect { value -> println(value) }
2424
println("Calling collect again...")

kotlinx-coroutines-core/jvm/test/guide/example-flow-06.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow06
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010

11-
fun foo(): Flow<Int> = flow {
11+
fun simple(): Flow<Int> = flow {
1212
for (i in 1..3) {
1313
delay(100)
1414
println("Emitting $i")
@@ -18,7 +18,7 @@ fun foo(): Flow<Int> = flow {
1818

1919
fun main() = runBlocking<Unit> {
2020
withTimeoutOrNull(250) { // Timeout after 250ms
21-
foo().collect { value -> println(value) }
21+
simple().collect { value -> println(value) }
2222
}
2323
println("Done")
2424
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-13.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import kotlinx.coroutines.flow.*
1010

1111
fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
1212

13-
fun foo(): Flow<Int> = flow {
14-
log("Started foo flow")
13+
fun simple(): Flow<Int> = flow {
14+
log("Started simple flow")
1515
for (i in 1..3) {
1616
emit(i)
1717
}
1818
}
1919

2020
fun main() = runBlocking<Unit> {
21-
foo().collect { value -> log("Collected $value") }
21+
simple().collect { value -> log("Collected $value") }
2222
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-14.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow14
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010

11-
fun foo(): Flow<Int> = flow {
11+
fun simple(): Flow<Int> = flow {
1212
// The WRONG way to change context for CPU-consuming code in flow builder
1313
kotlinx.coroutines.withContext(Dispatchers.Default) {
1414
for (i in 1..3) {
@@ -19,5 +19,5 @@ fun foo(): Flow<Int> = flow {
1919
}
2020

2121
fun main() = runBlocking<Unit> {
22-
foo().collect { value -> println(value) }
22+
simple().collect { value -> println(value) }
2323
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-15.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import kotlinx.coroutines.flow.*
1010

1111
fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
1212

13-
fun foo(): Flow<Int> = flow {
13+
fun simple(): Flow<Int> = flow {
1414
for (i in 1..3) {
1515
Thread.sleep(100) // pretend we are computing it in CPU-consuming way
1616
log("Emitting $i")
@@ -19,7 +19,7 @@ fun foo(): Flow<Int> = flow {
1919
}.flowOn(Dispatchers.Default) // RIGHT way to change context for CPU-consuming code in flow builder
2020

2121
fun main() = runBlocking<Unit> {
22-
foo().collect { value ->
22+
simple().collect { value ->
2323
log("Collected $value")
2424
}
2525
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-16.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010
import kotlin.system.*
1111

12-
fun foo(): Flow<Int> = flow {
12+
fun simple(): Flow<Int> = flow {
1313
for (i in 1..3) {
1414
delay(100) // pretend we are asynchronously waiting 100 ms
1515
emit(i) // emit next value
@@ -18,7 +18,7 @@ fun foo(): Flow<Int> = flow {
1818

1919
fun main() = runBlocking<Unit> {
2020
val time = measureTimeMillis {
21-
foo().collect { value ->
21+
simple().collect { value ->
2222
delay(300) // pretend we are processing it for 300 ms
2323
println(value)
2424
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-17.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010
import kotlin.system.*
1111

12-
fun foo(): Flow<Int> = flow {
12+
fun simple(): Flow<Int> = flow {
1313
for (i in 1..3) {
1414
delay(100) // pretend we are asynchronously waiting 100 ms
1515
emit(i) // emit next value
@@ -18,7 +18,7 @@ fun foo(): Flow<Int> = flow {
1818

1919
fun main() = runBlocking<Unit> {
2020
val time = measureTimeMillis {
21-
foo()
21+
simple()
2222
.buffer() // buffer emissions, don't wait
2323
.collect { value ->
2424
delay(300) // pretend we are processing it for 300 ms

kotlinx-coroutines-core/jvm/test/guide/example-flow-18.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010
import kotlin.system.*
1111

12-
fun foo(): Flow<Int> = flow {
12+
fun simple(): Flow<Int> = flow {
1313
for (i in 1..3) {
1414
delay(100) // pretend we are asynchronously waiting 100 ms
1515
emit(i) // emit next value
@@ -18,7 +18,7 @@ fun foo(): Flow<Int> = flow {
1818

1919
fun main() = runBlocking<Unit> {
2020
val time = measureTimeMillis {
21-
foo()
21+
simple()
2222
.conflate() // conflate emissions, don't process each one
2323
.collect { value ->
2424
delay(300) // pretend we are processing it for 300 ms

kotlinx-coroutines-core/jvm/test/guide/example-flow-19.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010
import kotlin.system.*
1111

12-
fun foo(): Flow<Int> = flow {
12+
fun simple(): Flow<Int> = flow {
1313
for (i in 1..3) {
1414
delay(100) // pretend we are asynchronously waiting 100 ms
1515
emit(i) // emit next value
@@ -18,7 +18,7 @@ fun foo(): Flow<Int> = flow {
1818

1919
fun main() = runBlocking<Unit> {
2020
val time = measureTimeMillis {
21-
foo()
21+
simple()
2222
.collectLatest { value -> // cancel & restart on the latest value
2323
println("Collecting $value")
2424
delay(300) // pretend we are processing it for 300 ms

kotlinx-coroutines-core/jvm/test/guide/example-flow-26.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow26
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010

11-
fun foo(): Flow<Int> = flow {
11+
fun simple(): Flow<Int> = flow {
1212
for (i in 1..3) {
1313
println("Emitting $i")
1414
emit(i) // emit next value
@@ -17,7 +17,7 @@ fun foo(): Flow<Int> = flow {
1717

1818
fun main() = runBlocking<Unit> {
1919
try {
20-
foo().collect { value ->
20+
simple().collect { value ->
2121
println(value)
2222
check(value <= 1) { "Collected $value" }
2323
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-27.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow27
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010

11-
fun foo(): Flow<String> =
11+
fun simple(): Flow<String> =
1212
flow {
1313
for (i in 1..3) {
1414
println("Emitting $i")
@@ -22,7 +22,7 @@ fun foo(): Flow<String> =
2222

2323
fun main() = runBlocking<Unit> {
2424
try {
25-
foo().collect { value -> println(value) }
25+
simple().collect { value -> println(value) }
2626
} catch (e: Throwable) {
2727
println("Caught $e")
2828
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-28.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow28
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010

11-
fun foo(): Flow<String> =
11+
fun simple(): Flow<String> =
1212
flow {
1313
for (i in 1..3) {
1414
println("Emitting $i")
@@ -21,7 +21,7 @@ fun foo(): Flow<String> =
2121
}
2222

2323
fun main() = runBlocking<Unit> {
24-
foo()
24+
simple()
2525
.catch { e -> emit("Caught $e") } // emit on exception
2626
.collect { value -> println(value) }
2727
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-29.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ package kotlinx.coroutines.guide.exampleFlow29
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010

11-
fun foo(): Flow<Int> = flow {
11+
fun simple(): Flow<Int> = flow {
1212
for (i in 1..3) {
1313
println("Emitting $i")
1414
emit(i)
1515
}
1616
}
1717

1818
fun main() = runBlocking<Unit> {
19-
foo()
19+
simple()
2020
.catch { e -> println("Caught $e") } // does not catch downstream exceptions
2121
.collect { value ->
2222
check(value <= 1) { "Collected $value" }

kotlinx-coroutines-core/jvm/test/guide/example-flow-30.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ package kotlinx.coroutines.guide.exampleFlow30
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010

11-
fun foo(): Flow<Int> = flow {
11+
fun simple(): Flow<Int> = flow {
1212
for (i in 1..3) {
1313
println("Emitting $i")
1414
emit(i)
1515
}
1616
}
1717

1818
fun main() = runBlocking<Unit> {
19-
foo()
19+
simple()
2020
.onEach { value ->
2121
check(value <= 1) { "Collected $value" }
2222
println(value)

kotlinx-coroutines-core/jvm/test/guide/example-flow-31.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ package kotlinx.coroutines.guide.exampleFlow31
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010

11-
fun foo(): Flow<Int> = (1..3).asFlow()
11+
fun simple(): Flow<Int> = (1..3).asFlow()
1212

1313
fun main() = runBlocking<Unit> {
1414
try {
15-
foo().collect { value -> println(value) }
15+
simple().collect { value -> println(value) }
1616
} finally {
1717
println("Done")
1818
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-32.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ package kotlinx.coroutines.guide.exampleFlow32
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010

11-
fun foo(): Flow<Int> = (1..3).asFlow()
11+
fun simple(): Flow<Int> = (1..3).asFlow()
1212

1313
fun main() = runBlocking<Unit> {
14-
foo()
14+
simple()
1515
.onCompletion { println("Done") }
1616
.collect { value -> println(value) }
1717
}

kotlinx-coroutines-core/jvm/test/guide/example-flow-33.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ package kotlinx.coroutines.guide.exampleFlow33
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010

11-
fun foo(): Flow<Int> = flow {
11+
fun simple(): Flow<Int> = flow {
1212
emit(1)
1313
throw RuntimeException()
1414
}
1515

1616
fun main() = runBlocking<Unit> {
17-
foo()
17+
simple()
1818
.onCompletion { cause -> if (cause != null) println("Flow completed exceptionally") }
1919
.catch { cause -> println("Caught exception") }
2020
.collect { value -> println(value) }

kotlinx-coroutines-core/jvm/test/guide/example-flow-34.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ package kotlinx.coroutines.guide.exampleFlow34
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.flow.*
1010

11-
fun foo(): Flow<Int> = (1..3).asFlow()
11+
fun simple(): Flow<Int> = (1..3).asFlow()
1212

1313
fun main() = runBlocking<Unit> {
14-
foo()
14+
simple()
1515
.onCompletion { cause -> println("Flow completed with $cause") }
1616
.collect { value ->
1717
check(value <= 1) { "Collected $value" }

kotlinx-coroutines-core/jvm/test/guide/test/FlowGuideTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class FlowGuideTest {
5050
@Test
5151
fun testExampleFlow05() {
5252
test("ExampleFlow05") { kotlinx.coroutines.guide.exampleFlow05.main() }.verifyLines(
53-
"Calling foo...",
53+
"Calling simple function...",
5454
"Calling collect...",
5555
"Flow started",
5656
"1",
@@ -139,7 +139,7 @@ class FlowGuideTest {
139139
@Test
140140
fun testExampleFlow13() {
141141
test("ExampleFlow13") { kotlinx.coroutines.guide.exampleFlow13.main() }.verifyLinesFlexibleThread(
142-
"[main @coroutine#1] Started foo flow",
142+
"[main @coroutine#1] Started simple flow",
143143
"[main @coroutine#1] Collected 1",
144144
"[main @coroutine#1] Collected 2",
145145
"[main @coroutine#1] Collected 3"

0 commit comments

Comments
 (0)