Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Throttle a flow using Akka Stream's new FlowGraph DSL
val rate = 200 millis
def throttled[T]: Flow[T, T] = {
val tickSource = TickSource(rate, rate, () => () )
val zip = Zip[T, Unit]
val in = UndefinedSource[T]
val out = UndefinedSink[T]
PartialFlowGraph{ implicit builder =>
import FlowGraphImplicits._
in ~> zip.left ~> Flow[(T,Unit)].map{ case (t, _) => t } ~> out
tickSource ~> zip.right
}.toFlow(in, out)

This comment has been minimized.

Copy link

akauppi commented Jun 2, 2016

Thanks. I think it's awkward that a .throttle method is not built-in in Akka Streams.

btw. note that the above is from the experimental akka streams era. See here for discussion on 2.4.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.