watch

Watch a specific ActorRef and signal a failure downstream once the actor terminates.

Actor interop operators

Signature

Source.watchSource.watch Flow.watchFlow.watch

Description

Watch a specific ActorRef and signal a failure downstream once the actor terminates. The signaled failure will be an WatchedActorTerminatedException WatchedActorTerminatedException.

Example

An ActorRef can be can be watched and the stream will fail with WatchedActorTerminatedException when the actor terminates.

Scala
val ref: ActorRef = someActor()
val flow: Flow[String, String, NotUsed] =
  Flow[String].watch(ref).recover {
    case _: WatchedActorTerminatedException => s"$ref terminated"
  }
Java
final ActorRef ref = someActor();
Flow<String, String, NotUsed> flow =
    Flow.of(String.class)
        .watch(ref)
        .recover(akka.stream.WatchedActorTerminatedException.class, () -> ref + " terminated");

Reactive Streams semantics

emits when upstream emits

backpressures when downstream backpressures

completes when upstream completes

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.