Skip to content

Proposal: Flow.collectLatest #1269

Closed
Closed
@BoxResin

Description

@BoxResin

Function signature

suspend fun <T> Flow<T>.collectLatest(action: suspend (value: T) -> Unit): Unit

Behavior

val flow = flowOf(1, 2, 3, 4, 5)
flow.collectLatest { value: Int -> // This lambda would be canceled if a new value is emitted although it hasn't been finished.
    delay(100)
    println(value) // So only '5' will be printed.
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions