throttle Time
Returns a Flow that emits a value from the source Flow, then ignores subsequent source values for a duration, then repeats this process for the next source value.
Example ThrottleConfiguration.LEADING:
(1..10)
.asFlow()
.onEach { delay(200) }
.throttleTime(500.milliseconds)
produces the following emissions
1, 4, 7, 10
Example ThrottleConfiguration.TRAILING:
(1..10)
.asFlow()
.onEach { delay(200) }
.throttleTime(500.milliseconds, TRAILING)
produces the following emissions
3, 6, 9, 10
(1..10)
.asFlow()
.onEach { delay(200) }
.throttleTime(500.milliseconds, LEADING_AND_TRAILING)
produces the following emissions
1, 3, 4, 6, 7, 9, 10
Returns a Flow that emits a value from the source Flow, then ignores subsequent source values for timeMillis milliseconds, then repeats this process for the next source value.
Example ThrottleConfiguration.LEADING:
(1..10)
.asFlow()
.onEach { delay(200) }
.throttleTime(500)
produces the following emissions
1, 4, 7, 10
Example ThrottleConfiguration.TRAILING:
(1..10)
.asFlow()
.onEach { delay(200) }
.throttleTime(500, TRAILING)
produces the following emissions
3, 6, 9, 10
(1..10)
.asFlow()
.onEach { delay(200) }
.throttleTime(500, LEADING_AND_TRAILING)
produces the following emissions
1, 3, 4, 6, 7, 9, 10
Returns a Flow that emits a value from the source Flow, then ignores subsequent source values for a duration determined by durationSelector, then repeats this process for the next source value.
Example ThrottleConfiguration.LEADING:
(1..10)
.asFlow()
.onEach { delay(200) }
.throttleTime { 500.milliseconds }
produces the following emissions
1, 4, 7, 10
Example ThrottleConfiguration.TRAILING:
(1..10)
.asFlow()
.onEach { delay(200) }
.throttleTime(TRAILING) { 500.milliseconds }
produces the following emissions
3, 6, 9, 10
(1..10)
.asFlow()
.onEach { delay(200) }
.throttleTime(LEADING_AND_TRAILING) { 500.milliseconds }
produces the following emissions
1, 3, 4, 6, 7, 9, 10