Last active
November 14, 2017 13:33
-
-
Save natewave/f96336097b97716c9bb7ce8411a00acb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
lazy val root = (project in file(".")). | |
settings( | |
inThisBuild(List( | |
organization := "io.github.natewave", | |
scalaVersion := "2.12.3", | |
version := "0.1.0-SNAPSHOT" | |
)), | |
name := "AkkaStreamsSample", | |
libraryDependencies ++= Seq( | |
"com.typesafe.akka" %% "akka-stream" % "2.5.6", | |
"com.typesafe.akka" %% "akka-stream-testkit" % "2.5.6" % Test | |
), | |
scalacOptions in Test ++= Seq("-Yrangepos") | |
) |
This file contains hidden or 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
package natewave | |
import akka.Done | |
import scala.concurrent.Future | |
import scala.util.{Failure, Success} | |
object GraphTest extends App { | |
import akka.actor.ActorSystem | |
import akka.stream._ | |
import akka.stream.scaladsl._ | |
override def main(args: Array[String]): Unit = { | |
// implicit actor system | |
implicit val system = ActorSystem() | |
// implicit actor materializer | |
implicit val materializer = ActorMaterializer() | |
import system.dispatcher | |
println("-- Main started! --") | |
val in1 = Source(List("a", "b", "c")) | |
val in2 = Source(List("d", "e", "f")) | |
val out = Sink.foreach(println) | |
import GraphDSL.Implicits._ | |
val graphShape = GraphDSL.create(out) { implicit b => sink => | |
val merge = b.add(Merge[String](2)) | |
in1 ~> merge.in(0) | |
in2 ~> merge.in(1) | |
merge.out ~> sink | |
ClosedShape | |
} | |
val graph: RunnableGraph[Future[Done]] = RunnableGraph.fromGraph(graphShape) | |
val run: Future[Done] = graph.run() | |
run.onComplete { | |
case Success(_) => system.terminate() | |
case Failure(e) => | |
println(e.getMessage) | |
system.terminate() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment