https://kotlinlang.org logo
#coroutines
Title
# coroutines
s

Shalom Halbert

11/07/2020, 8:30 AM
Is somebody able to share an explanation for why the test below prints
9a
9b
9c
9d
9e
9f
when it seemingly should be printing
1a
2a
3a
4a
5a
6a
7a
8a
before that?
Copy code
@Test
    fun example1(): Unit = runBlocking {
        val flowA = flowOf(1, 2, 3, 4, 5, 6, 7, 8, 9)
        val flowB = flowOf("a", "b", "c", "d", "e", "f").onEach { delay(1000) }

        flowA.combine(flowB) { a, b -> "$a$b" }.collect { println(it) }
    }
s

Shawn Witte

11/07/2020, 10:00 AM
Because
combine
uses the most recent values: https://kotlinlang.org/docs/reference/coroutines/flow.html#combine
s

Shalom Halbert

11/07/2020, 10:22 AM
Ah, didn’t give attention to the impact of a
delay
on the first value of
flowB
. Thank you 🙌
t

Tijl

11/07/2020, 1:27 PM
check out
zip
2
1
2 Views