Adding preMaterialize operator for Source #23894 (#24497)

This commit is contained in:
Stefano Bonetti 2018-02-21 06:06:01 +00:00 committed by Konrad `ktoso` Malawski
parent e44fafd4b7
commit 3ea59b1e76
7 changed files with 135 additions and 4 deletions

View file

@ -22,6 +22,7 @@ import org.junit.Test;
import scala.concurrent.duration.Duration;
import scala.concurrent.duration.FiniteDuration;
import akka.actor.ActorSystem;
import akka.actor.ActorRef;
import akka.actor.Cancellable;
import akka.dispatch.Futures;
import akka.stream.*;
@ -271,6 +272,22 @@ public class FlowDocTest extends AbstractJavaTest {
//#flow-mat-combine
}
@Test
public void sourcePreMaterialization() {
//#source-prematerialization
Source<String, ActorRef> matValuePoweredSource =
Source.actorRef(100, OverflowStrategy.fail());
Pair<ActorRef, Source<String, NotUsed>> actorRefSourcePair =
matValuePoweredSource.preMaterialize(mat);
actorRefSourcePair.first().tell("Hello!", ActorRef.noSender());
// pass source around for materialization
actorRefSourcePair.second().runWith(Sink.foreach(System.out::println), mat);
//#source-prematerialization
}
public void fusingAndAsync() {
//#flow-async
Source.range(1, 3)