Search code examples
javaakkaakka-stream

Akka. How to complete a stream with Source.actorRef?


I'd like to complete a stream with predefined messages count:

Source.actorRef(Integer.MAX_VALUE, OverflowStrategy.fail())
    .limit(1)
    .to(Sink.onComplete(System.out::println))
    .run(materializer);
    .tell("Do Complete!", ActorRef.noSender());

From the limit method documentation:

Completes when the defined number of elements has been taken or upstream completes

Why does stream not complete?


Solution

  • That is the documentation for take , not limit.

    And indeed, you should use take to solve your problem.