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

@ -42,6 +42,7 @@ import akka.stream.Attributes;
import java.time.Duration;
import java.util.Arrays;
import java.util.Comparator;
import java.util.concurrent.CompletableFuture;
class SourceOrFlow {
private static ActorSystem system = null;
@ -186,6 +187,21 @@ class SourceOrFlow {
// #scan
}
void scanAsyncExample() {
// #scanAsync
Source<Integer, NotUsed> source = Source.range(1, 5);
source
.scanAsync(0, (acc, x) -> CompletableFuture.completedFuture(acc + x))
.runForeach(System.out::println, materializer);
// 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
}
static // #conflateWithSeed-type
class Summed {