/**
* Delays the chunks of this stream according to the given bandwidth
* parameters using the token bucket algorithm. Allows for burst in the
* processing of elements by allowing the token bucket to accumulate tokens up
* to a `units + burst` threshold. The weight of each chunk is determined by
* the `costFn` function.
*
* @tsplus static effect/core/stream/Stream.Aspects throttleShape
* @tsplus pipeable effect/core/stream/Stream throttleShape
*/
export function throttleShape(
units: number,
duration: Duration,
costFn: (input: Chunk) => number,
burst = 0
) {
return (self: Stream): Stream =>
self.throttleShapeEffect(
units,
duration,
(input) => Effect.succeed(costFn(input)),
burst
)
}