Skip to content

Instantly share code, notes, and snippets.

@j5ik2o
Created February 28, 2019 10:47
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 j5ik2o/b73d2383b590ebcb5a95933a9a4b350a to your computer and use it in GitHub Desktop.
Save j5ik2o/b73d2383b590ebcb5a95933a9a4b350a to your computer and use it in GitHub Desktop.
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