metered

Flow that emits A every period while taking into account how much time it takes downstream to consume the emission. If downstream takes longer to process than period than it immediately emits another A.

Use onEach { delay(timeMillis) } for an alternative that sleeps period between every element. This is different in that the time between every element is equal to the specified period, regardless of how much time it takes to process that tick downstream.

i.e, for a period of 1 second and a delay(100), the timestamps of the emission would be 1s, 2s, 3s, ... when using fixedRate. Whereas with onEach { delay(timeMillis) } it would run at timestamps 1s, 2.1s, 3.2s, ...

Parameters

period

period between Unit emits of the resulting Flow.


fun <A> Flow<A>.metered(period: Long): Flow<A>(source)