@@ -523,7 +523,7 @@ pub struct ActorInstance<A: Actor> {
523523 /// Handle to the actor (used for lifecycle control and port access).
524524 pub handle : ActorHandle < A > ,
525525 /// Supervision events delivered to this actor.
526- pub supervision : PortReceiver < ActorSupervisionEvent > ,
526+ pub supervision : mpsc :: UnboundedReceiver < ActorSupervisionEvent > ,
527527 /// Control signals for the actor.
528528 pub signal : PortReceiver < Signal > ,
529529 /// Primary work queue for handler dispatch.
@@ -1814,7 +1814,10 @@ impl<A: Actor> Drop for InstanceState<A> {
18141814pub struct InstanceReceivers < A : Actor > {
18151815 /// Signal and supervision receivers for the actor loop. `None`
18161816 /// for detached/client instances that don't run an actor loop.
1817- actor_loop : Option < ( PortReceiver < Signal > , PortReceiver < ActorSupervisionEvent > ) > ,
1817+ actor_loop : Option < (
1818+ PortReceiver < Signal > ,
1819+ mpsc:: UnboundedReceiver < ActorSupervisionEvent > ,
1820+ ) > ,
18181821 /// Work queue for dispatching messages to actor handlers.
18191822 work : mpsc:: UnboundedReceiver < WorkCell < A > > ,
18201823 /// Introspect message receiver for the dedicated introspect task.
@@ -1854,10 +1857,10 @@ impl<A: Actor> Instance<A> {
18541857 None
18551858 } else {
18561859 let ( signal_port, signal_receiver) = mailbox. open_port :: < Signal > ( ) ;
1857- let ( supervision_port , supervision_receiver) =
1858- mailbox . open_port :: < ActorSupervisionEvent > ( ) ;
1860+ let ( supervision_tx , supervision_receiver) =
1861+ mpsc :: unbounded_channel :: < ActorSupervisionEvent > ( ) ;
18591862 Some ( (
1860- ( signal_port, supervision_port ) ,
1863+ ( signal_port, supervision_tx ) ,
18611864 ( signal_receiver, supervision_receiver) ,
18621865 ) )
18631866 } ;
@@ -2308,7 +2311,10 @@ impl<A: Actor> Instance<A> {
23082311 async fn serve (
23092312 mut self ,
23102313 mut actor : A ,
2311- actor_loop_receivers : ( PortReceiver < Signal > , PortReceiver < ActorSupervisionEvent > ) ,
2314+ actor_loop_receivers : (
2315+ PortReceiver < Signal > ,
2316+ mpsc:: UnboundedReceiver < ActorSupervisionEvent > ,
2317+ ) ,
23122318 mut work_rx : mpsc:: UnboundedReceiver < WorkCell < A > > ,
23132319 ) {
23142320 let result = self
@@ -2366,7 +2372,7 @@ impl<A: Actor> Instance<A> {
23662372 if let Some ( parent) = self . inner . cell . maybe_unlink_parent ( ) {
23672373 if let Some ( event) = event {
23682374 // Parent exists, failure should be propagated to the parent.
2369- parent. send_supervision_event_or_crash ( & self , event) ;
2375+ parent. send_supervision_event_or_crash ( event) ;
23702376 }
23712377 // TODO: we should get rid of this signal, and use *only* supervision events for
23722378 // the purpose of conveying lifecycle changes
@@ -2400,7 +2406,10 @@ impl<A: Actor> Instance<A> {
24002406 async fn run_actor_tree (
24012407 & mut self ,
24022408 actor : & mut A ,
2403- mut actor_loop_receivers : ( PortReceiver < Signal > , PortReceiver < ActorSupervisionEvent > ) ,
2409+ mut actor_loop_receivers : (
2410+ PortReceiver < Signal > ,
2411+ mpsc:: UnboundedReceiver < ActorSupervisionEvent > ,
2412+ ) ,
24042413 work_rx : & mut mpsc:: UnboundedReceiver < WorkCell < A > > ,
24052414 ) -> Result < String , ActorError > {
24062415 // It is okay to catch all panics here, because we are in a tokio task,
@@ -2519,7 +2528,10 @@ impl<A: Actor> Instance<A> {
25192528 async fn run (
25202529 & mut self ,
25212530 actor : & mut A ,
2522- actor_loop_receivers : & mut ( PortReceiver < Signal > , PortReceiver < ActorSupervisionEvent > ) ,
2531+ actor_loop_receivers : & mut (
2532+ PortReceiver < Signal > ,
2533+ mpsc:: UnboundedReceiver < ActorSupervisionEvent > ,
2534+ ) ,
25232535 work_rx : & mut mpsc:: UnboundedReceiver < WorkCell < A > > ,
25242536 ) -> Result < String , ActorError > {
25252537 let ( signal_receiver, supervision_event_receiver) = actor_loop_receivers;
@@ -2572,7 +2584,7 @@ impl<A: Actor> Instance<A> {
25722584 let _ = ACTOR_MESSAGE_HANDLER_DURATION . start( metric_pairs) ;
25732585 let work = work. expect( "inconsistent work queue state" ) ;
25742586 if let Err ( err) = work. handle( actor, self ) . await {
2575- for supervision_event in supervision_event_receiver. drain ( ) {
2587+ while let Ok ( supervision_event) = supervision_event_receiver. try_recv ( ) {
25762588 self . handle_supervision_event( actor, supervision_event) . await ?;
25772589 }
25782590 let kind = ActorErrorKind :: processing( err) ;
@@ -2582,7 +2594,7 @@ impl<A: Actor> Instance<A> {
25822594 } ) ;
25832595 }
25842596 }
2585- Ok ( supervision_event) = supervision_event_receiver. recv( ) => {
2597+ Some ( supervision_event) = supervision_event_receiver. recv( ) => {
25862598 self . handle_supervision_event( actor, supervision_event) . await ?;
25872599 }
25882600 }
@@ -2971,7 +2983,10 @@ struct InstanceCellState {
29712983 proc : Proc ,
29722984
29732985 /// Control port handles to the actor loop, if one is running.
2974- actor_loop : Option < ( PortHandle < Signal > , PortHandle < ActorSupervisionEvent > ) > ,
2986+ actor_loop : Option < (
2987+ PortHandle < Signal > ,
2988+ mpsc:: UnboundedSender < ActorSupervisionEvent > ,
2989+ ) > ,
29752990
29762991 /// An observer that stores the current status of the actor.
29772992 status : watch:: Receiver < ActorStatus > ,
@@ -3120,7 +3135,10 @@ impl InstanceCell {
31203135 actor_id : ActorAddr ,
31213136 actor_type : ActorType ,
31223137 proc : Proc ,
3123- actor_loop : Option < ( PortHandle < Signal > , PortHandle < ActorSupervisionEvent > ) > ,
3138+ actor_loop : Option < (
3139+ PortHandle < Signal > ,
3140+ mpsc:: UnboundedSender < ActorSupervisionEvent > ,
3141+ ) > ,
31243142 status : watch:: Receiver < ActorStatus > ,
31253143 parent : Option < InstanceCell > ,
31263144 ports : Arc < dyn Any + Send + Sync > ,
@@ -3229,14 +3247,10 @@ impl InstanceCell {
32293247 /// Note that "let it crash" is the default behavior when a supervision event
32303248 /// cannot be delivered upstream. It is the upstream's responsibility to
32313249 /// detect and handle crashes.
3232- pub fn send_supervision_event_or_crash (
3233- & self ,
3234- child_cx : & impl context:: Actor , // context of the child who sends the event.
3235- event : ActorSupervisionEvent ,
3236- ) {
3250+ pub fn send_supervision_event_or_crash ( & self , event : ActorSupervisionEvent ) {
32373251 match & self . inner . actor_loop {
3238- Some ( ( _, supervision_port ) ) => {
3239- if let Err ( err) = supervision_port . send ( child_cx , event. clone ( ) ) {
3252+ Some ( ( _, supervision_tx ) ) => {
3253+ if let Err ( err) = supervision_tx . send ( event. clone ( ) ) {
32403254 if !event. is_error ( ) {
32413255 // Normal lifecycle events (e.g. clean stop) that fail to
32423256 // send are silently dropped. This happens when a child
0 commit comments