parent
5605f04cb7
commit
37d87811b5
3 changed files with 53 additions and 1 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package jdocs.stream.operators;
|
||||
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.japi.pf.PFBuilder;
|
||||
import akka.stream.javadsl.Flow;
|
||||
|
|
@ -41,7 +42,6 @@ import akka.stream.Attributes;
|
|||
// #log
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
|
@ -426,4 +426,18 @@ class SourceOrFlow {
|
|||
// -1
|
||||
// #dropWhile
|
||||
}
|
||||
|
||||
void watchExample() {
|
||||
// #watch
|
||||
final ActorRef ref = someActor();
|
||||
Flow<String, String, NotUsed> flow =
|
||||
Flow.of(String.class)
|
||||
.watch(ref)
|
||||
.recover(akka.stream.WatchedActorTerminatedException.class, () -> ref + " terminated");
|
||||
// #watch
|
||||
}
|
||||
|
||||
private ActorRef someActor() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (C) 2019-2020 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.stream.operators.sourceorflow
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.actor.ActorRef
|
||||
import akka.stream.WatchedActorTerminatedException
|
||||
import akka.stream.scaladsl.Flow
|
||||
|
||||
object Watch {
|
||||
|
||||
def someActor(): ActorRef = ???
|
||||
|
||||
def watchExample(): Unit = {
|
||||
//#watch
|
||||
val ref: ActorRef = someActor()
|
||||
val flow: Flow[String, String, NotUsed] =
|
||||
Flow[String].watch(ref).recover {
|
||||
case _: WatchedActorTerminatedException => s"$ref terminated"
|
||||
}
|
||||
//#watch
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue