watch
Watch a specific ActorRef
and signal a failure downstream once the actor terminates.
Signature
Source.watch
Source.watch
Flow.watch
Flow.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
-
source
val ref: ActorRef = someActor() val flow: Flow[String, String, NotUsed] = Flow[String].watch(ref).recover { case _: WatchedActorTerminatedException => s"$ref terminated" }
- Java
-
source
final ActorRef ref = someActor(); Flow<String, String, NotUsed> flow = Flow.of(String.class) .watch(ref) .recover( org.apache.pekko.stream.WatchedActorTerminatedException.class, () -> ref + " terminated");
Reactive Streams semantics
emits when upstream emits
backpressures when downstream backpressures
completes when upstream completes
1.1.2+24-bcd44ee3*