Created
February 28, 2019 10:47
-
-
Save j5ik2o/b73d2383b590ebcb5a95933a9a4b350a to your computer and use it in GitHub Desktop.
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
object TestMain extends App { | |
import akka.stream.scaladsl._ | |
import akka.actor._ | |
import akka.stream.ActorMaterializer | |
import scala.concurrent._ | |
import scala.concurrent.duration._ | |
implicit val system = ActorSystem() | |
implicit val ec = system.dispatcher | |
implicit val mat = ActorMaterializer() | |
val future = Source(1 to 20000) | |
.batch(max = 30, first => Seq(first)) { (batch, elem) => | |
batch :+ elem // 下流が遅いときに要素がまとめられる | |
} | |
.runWith(Sink.foreach { x => | |
Thread.sleep(4000) | |
println("Out:" + x) | |
}) | |
Await.result(future, Duration.Inf) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment