Implements actorRef source variant with backpressure #17610 (#26633)

* Implements actorRef source variant with backpressure #17610

* Small improvements to documentation and source #17610

* Small improvements to test #17610

* Small improvements to implementation and tests #17610

* Adds API for akka-typed #17610

* Adds ack sender and java api for typed #17610
This commit is contained in:
Nicolas Vollmar 2019-05-20 12:19:44 +02:00 committed by Patrik Nordwall
parent a9f4f2dd96
commit f37f41574d
14 changed files with 472 additions and 6 deletions

View file

@ -6,6 +6,7 @@ package docs.stream.operators
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.testkit.TestProbe
object SourceOperators {
@ -35,6 +36,7 @@ object SourceOperators {
import akka.actor.Status.Success
import akka.actor.ActorRef
import akka.stream.OverflowStrategy
import akka.stream.CompletionStrategy
import akka.stream.scaladsl._
implicit val system: ActorSystem = ActorSystem()
@ -48,7 +50,32 @@ object SourceOperators {
actorRef ! "hello"
// The stream completes successfully with the following message
actorRef ! Success("completes stream")
actorRef ! Success(CompletionStrategy.immediately)
//#actorRef
}
def actorRefWithAck(): Unit = {
//#actorRefWithAck
import akka.actor.Status.Success
import akka.actor.ActorRef
import akka.stream.CompletionStrategy
import akka.stream.scaladsl._
implicit val system: ActorSystem = ActorSystem()
implicit val materializer: ActorMaterializer = ActorMaterializer()
val probe = TestProbe()
val source: Source[Any, ActorRef] = Source.actorRefWithAck[Any]("ack")
val actorRef: ActorRef = source.to(Sink.foreach(println)).run()
probe.send(actorRef, "hello")
probe.expectMsg("ack")
probe.send(actorRef, "hello")
probe.expectMsg("ack")
// The stream completes successfully with the following message
actorRef ! Success(CompletionStrategy.immediately)
//#actorRefWithAck
}
}