Created
December 3, 2014 15:06
-
-
Save inanna-malick/7836aa4f1ea7d04eb033 to your computer and use it in GitHub Desktop.
Throttle a flow using Akka Stream's new FlowGraph DSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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