Add scanAsync examples to akka-docs (#25468) (#27990)

* Add scanAsync examples to akka-docs (#25468)

* Sync scan with scanAsync in akka-docs (#25468)
This commit is contained in:
Lim Chee Hau 2019-11-26 10:57:12 +01:00 committed by Arnout Engelen
parent 2ee63f5386
commit 444a86291e
4 changed files with 77 additions and 3 deletions

View file

@ -0,0 +1,28 @@
/*
* Copyright (C) 2019 Lightbend Inc. <https://www.lightbend.com>
*/
package docs.stream.operators.sourceorflow
import akka.stream.scaladsl.Source
import scala.concurrent.Future
object ScanAsync {
def scanAsyncExample(): Unit = {
import akka.actor.ActorSystem
implicit val system: ActorSystem = ActorSystem()
//#scanAsync
val source = Source(1 to 5)
source.scanAsync(0)((acc, x) => Future.successful(acc + x)).runForeach(println)
// 0 (= 0)
// 1 (= 0 + 1)
// 3 (= 0 + 1 + 2)
// 6 (= 0 + 1 + 2 + 3)
// 10 (= 0 + 1 + 2 + 3 + 4)
// 15 (= 0 + 1 + 2 + 3 + 4 + 5)
//#scanAsync
}
}