Skip to content

Rename 'foo' function to 'simple' in flow docs #2078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 64 additions & 64 deletions docs/flow.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-01.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-02.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
// 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
}
}

fun main() {
foo().forEach { value -> println(value) }
simple().forEach { value -> println(value) }
}
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-03.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ package kotlinx.coroutines.guide.exampleFlow03

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) }
}
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-04.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow04
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
Expand All @@ -24,5 +24,5 @@ fun main() = runBlocking<Unit> {
}
}
// Collect the flow
foo().collect { value -> println(value) }
simple().collect { value -> println(value) }
}
6 changes: 3 additions & 3 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-05.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow05
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)
Expand All @@ -17,8 +17,8 @@ fun foo(): Flow<Int> = flow {
}

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...")
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-06.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow06
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")
Expand All @@ -18,7 +18,7 @@ fun foo(): Flow<Int> = flow {

fun main() = runBlocking<Unit> {
withTimeoutOrNull(250) { // Timeout after 250ms
foo().collect { value -> println(value) }
simple().collect { value -> println(value) }
}
println("Done")
}
6 changes: 3 additions & 3 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-13.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import kotlinx.coroutines.flow.*

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") }
}
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-14.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow14
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) {
Expand All @@ -19,5 +19,5 @@ fun foo(): Flow<Int> = flow {
}

fun main() = runBlocking<Unit> {
foo().collect { value -> println(value) }
simple().collect { value -> println(value) }
}
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-15.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.coroutines.flow.*

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")
Expand All @@ -19,7 +19,7 @@ fun foo(): Flow<Int> = flow {
}.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")
}
}
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-16.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.*
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
Expand All @@ -18,7 +18,7 @@ fun foo(): Flow<Int> = flow {

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)
}
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-17.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.*
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
Expand All @@ -18,7 +18,7 @@ fun foo(): Flow<Int> = flow {

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
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-18.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.*
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
Expand All @@ -18,7 +18,7 @@ fun foo(): Flow<Int> = flow {

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
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-19.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.*
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
Expand All @@ -18,7 +18,7 @@ fun foo(): Flow<Int> = flow {

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
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-26.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow26
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
Expand All @@ -17,7 +17,7 @@ fun foo(): Flow<Int> = flow {

fun main() = runBlocking<Unit> {
try {
foo().collect { value ->
simple().collect { value ->
println(value)
check(value <= 1) { "Collected $value" }
}
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-27.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow27
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*

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

fun main() = runBlocking<Unit> {
try {
foo().collect { value -> println(value) }
simple().collect { value -> println(value) }
} catch (e: Throwable) {
println("Caught $e")
}
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-28.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package kotlinx.coroutines.guide.exampleFlow28
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*

fun foo(): Flow<String> =
fun simple(): Flow<String> =
flow {
for (i in 1..3) {
println("Emitting $i")
Expand All @@ -21,7 +21,7 @@ fun foo(): Flow<String> =
}

fun main() = runBlocking<Unit> {
foo()
simple()
.catch { e -> emit("Caught $e") } // emit on exception
.collect { value -> println(value) }
}
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-29.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ package kotlinx.coroutines.guide.exampleFlow29
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)
}
}

fun main() = runBlocking<Unit> {
foo()
simple()
.catch { e -> println("Caught $e") } // does not catch downstream exceptions
.collect { value ->
check(value <= 1) { "Collected $value" }
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-30.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ package kotlinx.coroutines.guide.exampleFlow30
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)
}
}

fun main() = runBlocking<Unit> {
foo()
simple()
.onEach { value ->
check(value <= 1) { "Collected $value" }
println(value)
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-31.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ package kotlinx.coroutines.guide.exampleFlow31
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")
}
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-32.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ package kotlinx.coroutines.guide.exampleFlow32
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) }
}
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-33.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ package kotlinx.coroutines.guide.exampleFlow33
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) }
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/example-flow-34.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ package kotlinx.coroutines.guide.exampleFlow34
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" }
Expand Down
4 changes: 2 additions & 2 deletions kotlinx-coroutines-core/jvm/test/guide/test/FlowGuideTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class FlowGuideTest {
@Test
fun testExampleFlow05() {
test("ExampleFlow05") { kotlinx.coroutines.guide.exampleFlow05.main() }.verifyLines(
"Calling foo...",
"Calling simple function...",
"Calling collect...",
"Flow started",
"1",
Expand Down Expand Up @@ -139,7 +139,7 @@ class FlowGuideTest {
@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"
Expand Down