debounce

@FlowPreview fun <T> Flow<T>.debounce(
    timeoutMillis: Long
): Flow<T>
(source)

Returns a flow that mirrors the original flow, but filters out values that are followed by the newer values within the given timeout. The latest value is always emitted.

Example:

flow {
    emit(1)
    delay(90)
    emit(2)
    delay(90)
    emit(3)
    delay(1010)
    emit(4)
    delay(1010)
    emit(5)
}.debounce(1000)

produces 3, 4, 5.

Note that the resulting flow does not emit anything as long as the original flow emits items faster than every timeoutMillis milliseconds.