Skip to content

Instantly share code, notes, and snippets.

@ticofab
Created July 15, 2018 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ticofab/3d43f1c98aac65a40ca9227db9368e29 to your computer and use it in GitHub Desktop.
Save ticofab/3d43f1c98aac65a40ca9227db9368e29 to your computer and use it in GitHub Desktop.
val bcMappingFlow = Flow.fromGraph(GraphDSL.create() { implicit b =>
import GraphDSL.Implicits._
val bc = b.add(Broadcast[Int](2))
val printSink = Sink.foreach(println)
bc.out(1).map(i => i * 2) ~> printSink
FlowShape(bc.in, bc.out(0))
})
Source(1 to 10)
.via(bcMappingFlow)
.runForeach(n => println("runForeach, received: " + n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment