added examples for Stream # actorRef operator. As part of #25468 (#26162)

This commit is contained in:
Seeta Ramayya 2019-01-02 17:08:35 +01:00 committed by Johan Andrén
parent 6cca1a0ee3
commit f8618b24b0
3 changed files with 60 additions and 1 deletions

View file

@ -4,6 +4,9 @@
package docs.stream.operators
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
object SourceOperators {
def fromFuture = {
@ -11,8 +14,8 @@ object SourceOperators {
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.{ Done, NotUsed }
import akka.stream.scaladsl._
import akka.{ Done, NotUsed }
import scala.concurrent.Future
@ -25,4 +28,27 @@ object SourceOperators {
val done: Future[Done] = source.runWith(sink) //10
//#sourceFromFuture
}
def actorRef(): Unit = {
//#actorRef
import akka.actor.Status.Success
import akka.actor.ActorRef
import akka.stream.OverflowStrategy
import akka.stream.scaladsl._
implicit val system: ActorSystem = ActorSystem()
implicit val materializer: ActorMaterializer = ActorMaterializer()
val bufferSize = 100
val source: Source[Any, ActorRef] = Source.actorRef[Any](bufferSize, OverflowStrategy.dropHead)
val actorRef: ActorRef = source.to(Sink.foreach(println)).run()
actorRef ! "hello"
actorRef ! "hello"
// The stream completes successfully with the following message
actorRef ! Success("completes stream")
//#actorRef
}
}