2018-05-27 21:49:12 -03:00
|
|
|
/*
|
2020-01-02 07:24:59 -05:00
|
|
|
* Copyright (C) 2018-2020 Lightbend Inc. <https://www.lightbend.com>
|
2018-05-27 21:49:12 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package docs.stream
|
|
|
|
|
|
|
|
|
|
import akka.stream.scaladsl.{ Sink, Source }
|
|
|
|
|
import docs.stream.cookbook.RecipeSpec
|
|
|
|
|
|
|
|
|
|
import scala.concurrent.Future
|
|
|
|
|
|
|
|
|
|
class SinkRecipeDocSpec extends RecipeSpec {
|
|
|
|
|
"Sink.foreachAsync" must {
|
|
|
|
|
"processing each element asynchronously" in {
|
|
|
|
|
def asyncProcessing(value: Int): Future[Unit] = Future { println(value) }(system.dispatcher)
|
|
|
|
|
//#forseachAsync-processing
|
|
|
|
|
//def asyncProcessing(value: Int): Future[Unit] = _
|
|
|
|
|
|
2019-03-11 10:38:24 +01:00
|
|
|
Source(1 to 100).runWith(Sink.foreachAsync(10)(asyncProcessing))
|
2018-05-27 21:49:12 -03:00
|
|
|
//#forseachAsync-processing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|