This is a question I’ve asked previously in Stack Overflow
Looking at the signature of throttle in Akka Streams I see that it can take a cost function of type (Out) ⇒ Int to compute how the element passing through the stage affects the cost/per speed limit of elements sent downstream.
Is it possible to implement throttling based on external input for the stream with a built-in stage? If not, would it be easier just to implement a custom stage?
What about taking Source.tick for periodic elements and then combining that with throttle, but implementing costCalculation to refer to some external input to calculate the cost. That would produce a stream of ticks that is throttled by some external input. This stream then can be zipped with some other stream that needs to be throttled.
Thanks for the reply @2m. I’m not quite sure what you mean by combining Source.tick and throttle. The costCalculation would still be per element passing through this combined stream though?
Do you have an example of how that might look like?
I don’t, but I was hoping that the defined granularity would not dictate the max rate of elements passing through the stream. Maybe I’m mistaken, but I was under the impression that combining 2 streams would make the stream progress at the rate of the slowest stream.
I’m guessing I would have to use something like conflate for making tick stream catch up if it has to?