@@ -490,7 +490,7 @@ impl Proc {
490
490
/// Call `abort` on the `JoinHandle` associated with the given
491
491
/// root actor. If successful return `Some(root.clone())` else
492
492
/// `None`.
493
- pub fn abort_root_actor ( & mut self , root : & ActorId ) -> Option < ActorId > {
493
+ pub fn abort_root_actor ( & self , root : & ActorId ) -> Option < ActorId > {
494
494
self . state ( )
495
495
. ledger
496
496
. roots
@@ -511,17 +511,12 @@ impl Proc {
511
511
. next ( )
512
512
}
513
513
514
- // Iterating over a proc's root actors signaling each to stop.
515
- // Return the root actor IDs and status observers.
516
- async fn destroy (
517
- & mut self ,
518
- ) -> Result < HashMap < ActorId , watch:: Receiver < ActorStatus > > , anyhow:: Error > {
519
- tracing:: debug!( "{}: proc stopping" , self . proc_id( ) ) ;
520
-
521
- let mut statuses = HashMap :: new ( ) ;
522
- for entry in self . state ( ) . ledger . roots . iter ( ) {
514
+ /// Signals to a root actor to stop,
515
+ /// returning a status observer if successful.
516
+ pub fn stop_actor ( & self , actor_id : & ActorId ) -> Option < watch:: Receiver < ActorStatus > > {
517
+ if let Some ( entry) = self . state ( ) . ledger . roots . get ( actor_id) {
523
518
match entry. value ( ) . upgrade ( ) {
524
- None => ( ) , // the root's cell has been dropped
519
+ None => None , // the root's cell has been dropped
525
520
Some ( cell) => {
526
521
tracing:: info!( "sending stop signal to {}" , cell. actor_id( ) ) ;
527
522
if let Err ( err) = cell. signal ( Signal :: DrainAndStop ) {
@@ -531,15 +526,16 @@ impl Proc {
531
526
cell. pid( ) ,
532
527
err
533
528
) ;
534
- continue ;
529
+ None
530
+ } else {
531
+ Some ( cell. status ( ) . clone ( ) )
535
532
}
536
- statuses. insert ( cell. actor_id ( ) . clone ( ) , cell. status ( ) . clone ( ) ) ;
537
533
}
538
534
}
535
+ } else {
536
+ tracing:: error!( "no actor {} found in {} roots" , actor_id, self . proc_id( ) ) ;
537
+ None
539
538
}
540
-
541
- tracing:: debug!( "{}: proc stopped" , self . proc_id( ) ) ;
542
- Ok ( statuses)
543
539
}
544
540
545
541
/// Stop the proc. Returns a pair of:
@@ -553,7 +549,23 @@ impl Proc {
553
549
timeout : Duration ,
554
550
skip_waiting : Option < & ActorId > ,
555
551
) -> Result < ( Vec < ActorId > , Vec < ActorId > ) , anyhow:: Error > {
556
- let mut statuses = self . destroy ( ) . await ?;
552
+ tracing:: debug!( "{}: proc stopping" , self . proc_id( ) ) ;
553
+
554
+ let mut statuses = HashMap :: new ( ) ;
555
+ for actor_id in self
556
+ . state ( )
557
+ . ledger
558
+ . roots
559
+ . iter ( )
560
+ . map ( |entry| entry. key ( ) . clone ( ) )
561
+ . collect :: < Vec < _ > > ( )
562
+ {
563
+ if let Some ( status) = self . stop_actor ( & actor_id) {
564
+ statuses. insert ( actor_id, status) ;
565
+ }
566
+ }
567
+ tracing:: debug!( "{}: proc stopped" , self . proc_id( ) ) ;
568
+
557
569
let waits: Vec < _ > = statuses
558
570
. iter_mut ( )
559
571
. filter ( |( actor_id, _) | Some ( * actor_id) != skip_waiting)
0 commit comments