sample

@FlowPreview fun <T> Flow<T>.sample(
    periodMillis: Long
): Flow<T>
(source)

Returns a flow that emits only the latest value emitted by the original flow during the given sampling period.

Example:

flow {
    repeat(10) {
        emit(it)
        delay(50)
    }
}.sample(100)

produces 1, 3, 5, 7, 9.

Note that the latest element is not emitted if it does not fit into the sampling window.