Hello everyone, does anyone could help me understa...
# coroutines
n
Hello everyone, does anyone could help me understand why
collectLatest
wont cancel coroutine launched in its block, saying
Copy code
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
Copy code
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