throttle
Throttles the emission of elements from the Flow based on the specified elementsPerInterval, interval, and strategy.
Return
A new Flow with throttling applied based on the specified parameters.
Example usage:
flowOf(1, 2, 3, 4, 5)
.throttle(elementsPerInterval = 2, interval = 1.seconds, strategy = ThrottleStrategy.Suspend)
// Output: 1, 2, (1s delay), 3, 4, (1s delay), 5
Parameters
The maximum number of elements allowed to be emitted per interval.
A Duration specifying the time interval for throttling the flow.
The ThrottleStrategy to apply when the flow exceeds the specified rate. Defaults to ThrottleStrategy.Suspend. ThrottleStrategy.Suspend will suspend the emission until the next interval. ThrottleStrategy.Drop will drop the element if the rate is exceeded.
Throttles the emission of elements from the Flow based on the specified semaphore, interval, and strategy.
Return
A new Flow with throttling applied based on the specified parameters.
Example usage:
flowOf(1, 2, 3, 4, 5)
.throttle(strategy = ThrottleStrategy.Suspend) {
// custom semaphore implementation
}
Parameters
The ThrottleStrategy to apply when the flow exceeds the specified rate. Defaults to ThrottleStrategy.Suspend. ThrottleStrategy.Suspend will suspend the emission until the next interval. ThrottleStrategy.Drop will drop the element if the rate is exceeded.
The AsyncSemaphore that controls the emission of the elements.