Update Source.actorRef sample to not use deprecated method #28679
This commit is contained in:
parent
7d790ef328
commit
6f23b1fb4b
3 changed files with 27 additions and 10 deletions
|
|
@ -6,6 +6,7 @@ package jdocs.stream.operators;
|
|||
|
||||
// #imports
|
||||
// #range-imports
|
||||
import akka.Done;
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.actor.testkit.typed.javadsl.ManualTime;
|
||||
|
|
@ -81,7 +82,17 @@ public class SourceDocExamples {
|
|||
// #actor-ref
|
||||
|
||||
int bufferSize = 100;
|
||||
Source<Object, ActorRef> source = Source.actorRef(bufferSize, OverflowStrategy.dropHead());
|
||||
Source<Object, ActorRef> source =
|
||||
Source.actorRef(
|
||||
elem -> {
|
||||
// complete stream immediately if we send it Done
|
||||
if (elem == Done.done()) return Optional.of(CompletionStrategy.immediately());
|
||||
else return Optional.empty();
|
||||
},
|
||||
// never fail the stream because of a message
|
||||
elem -> Optional.empty(),
|
||||
bufferSize,
|
||||
OverflowStrategy.dropHead());
|
||||
|
||||
ActorRef actorRef = source.to(Sink.foreach(System.out::println)).run(system);
|
||||
actorRef.tell("hello", ActorRef.noSender());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue