Natsuki(开元米粉实力代购)
03/22/2021, 7:51 AMcollectLatest
wont cancel coroutine launched in its block, saying
flow {
emit(1)
delay(100L)
emit(2)
delay(100L)
emit(3)
delay(100L)
}.collectLatest { value ->
launch {
println("start: $value")
while(true) {
delay(200L)
println("loop: $value")
}
}
}
will print loop:1
and loop:2
and loop:3
forever (which i think should not be the desired behavior)
while
flow {
emit(1)
delay(100L)
emit(2)
delay(100L)
emit(3)
delay(100L)
}.collectLatest { value ->
coroutineScope {
println("start: $value")
while(true) {
delay(200L)
println("loop: $value")
}
}
}
will always print loop: 3
after a seconds later