=str #19299 Performance Flow.flatMapMerge

This commit is contained in:
Alexander Golubev 2016-02-02 16:39:47 -05:00
parent ad8ab128c4
commit b2b2ce44b5
19 changed files with 224 additions and 134 deletions

View file

@ -443,23 +443,22 @@ public class GraphStageDocTest extends AbstractJavaTest {
public void demonstrateAnAsynchronousSideChannel() throws Exception{
// tests:
TestSubscriber.Probe<Integer> out = TestSubscriber.probe(system);
TestPublisher.Probe<Integer> in = TestPublisher.probe(0, system);
CompletableFuture<Done> switchF = new CompletableFuture<>();
Graph<FlowShape<Integer, Integer>, NotUsed> killSwitch =
Flow.fromGraph(new KillSwitch<>(switchF));
ExecutionContext ec = system.dispatcher();
Source.fromPublisher(in).via(killSwitch).to(Sink.fromSubscriber(out)).run(mat);
CompletionStage<Integer> valueAfterKill = switchF.thenApply(in -> 4);
CompletionStage<Integer> result =
Source.from(Arrays.asList(1, 2, 3)).concat(Source.fromCompletionStage(valueAfterKill))
.via(killSwitch)
.runFold(0, (n, sum) -> n + sum, mat);
out.request(1);
in.sendNext(1);
out.expectNext(1);
switchF.complete(Done.getInstance());
assertEquals(new Integer(6), result.toCompletableFuture().get(3, TimeUnit.SECONDS));
out.expectComplete();
}

View file

@ -272,7 +272,6 @@ class GraphStageDocSpec extends AkkaSpec {
"Demonstrate an asynchronous side channel" in {
import system.dispatcher
//#async-side-channel
// will close upstream in all materializations of the graph stage instance
// when the future completes