Skip to content

Instantly share code, notes, and snippets.

@amoilanen
Created March 11, 2018 22:25
Show Gist options
  • Save amoilanen/baebef9dabea345e37d04b55a8f8d532 to your computer and use it in GitHub Desktop.
Save amoilanen/baebef9dabea345e37d04b55a8f8d532 to your computer and use it in GitHub Desktop.
Simple example of a stream in Akka: source -> flow -> sink
import akka.actor.ActorSystem
import akka.stream.scaladsl._
import akka.stream._
object AkkaStreamExample extends App {
implicit val system = ActorSystem("MyActorSystem")
implicit val materializer = ActorMaterializer()
val source = Source(1 to 5)
val square = Flow[Int].map(x => x * x)
val sink = Sink.foreach[Int](println)
(source via square to sink).run
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment