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
Source(List(1, 2, 3, 4)) | |
.map(_ * 2) | |
.withAttributes(supervisionStrategy(Supervision.resumingDecider)) | |
.map(i => if (i == 2) throw new IllegalStateException("error")) | |
.runWith(Sink.ignore) |
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
Source(List(1, 2, 3, 4)) | |
.map(_ * 2) | |
.withAttributes(supervisionStrategy(Supervision.resumingDecider)) | |
.map(i => if (i == 2) throw new IllegalStateException("error")) | |
.runWith(Sink.ignore) |
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
Source(infiniteTransactionsStream) | |
.log(“got transaction”) |
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
def saveHashAndReturnIt(hash: String): Future[String] = Future { | |
if (Random.nextInt(5) == 1) { | |
Thread.sleep(100000) //simulate database unavailability | |
} | |
hash | |
} |
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
Source(1 to 5) | |
.alsoTo(Sink.foreach{x => | |
Thread.sleep(100) | |
println(s”elem:$x alsoTo”)} | |
) | |
.map { x => | |
println(s”elem:$x map”) | |
x | |
} | |
.to(Sink.foreach(x => println(s”elem:$x to”))) |
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 roomsTemperatureReadings = | |
Stream.continually(TemperatureReading(randomRoom, randomTemperature)) | |
Source(roomsTemperatureReadings) | |
.alsoTo(Sink.foreach(reading => createRoomIfNotExist(reading.roomId))) | |
.to(Sink.foreach(saveReading)) | |
.run() |
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
Source(List("1","2","a","4","5")) | |
.map(_.toInt) | |
.withAttributes(ActorAttributes.supervisionStrategy(Supervision.resumingDecider)) | |
.runForeach(println) |
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 nonLinearFlow = Flow.fromGraph(GraphDSL.create() { implicit builder => | |
import GraphDSL.Implicits._ | |
val dangerousFlow = Flow[Int].map { | |
case 5 => throw new RuntimeException(“BOOM!”) | |
case x => x | |
} | |
val safeFlow = Flow[Int] |
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
Source(1 to 10) | |
.via(nonLinearFlow) | |
.withAttributes(ActorAttributes.supervisionStrategy(Supervision.resumingDecider)) | |
.runForeach(println) |
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 dangerousFlow = Flow[Int].map { | |
case 5 => Failure(new RuntimeException(“BOOM!”)) | |
case x => Try(x) | |
} | |
val safeFlow = Flow[Int].map(Try(_)) | |
val bcast = builder.add(Broadcast[Int](2)) | |
val zip = builder.add(Zip[Try[Int], Try[Int]]) |
OlderNewer