Skip to content

collectLatest does not cancel runInterruptible if dispatchers are the same #3109

@aasitnikov

Description

@aasitnikov
val flow = flowOf(1, 2)
launch(Dispatchers.IO) {
    flow.collectLatest {
        println("start $it")
        runInterruptible(Dispatchers.IO) {
            Thread.sleep(5000)
            println("Finish interruptible")
        }
        if (it == 1) throw Exception("unexpected")
    }
}

I expect this code to print
start 1
start 2
finish interruptible

But instead it prints
start 1
finish interruptible
exception java.lang.Exception: unexpected

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions