@@ -27,7 +27,7 @@ type EmittedEvent[Event any] struct {
2727	// InternalEvent is an optional internal event that is to be routed 
2828	// back to the target state. This enables state to trigger one or many 
2929	// state transitions without a new external event. 
30- 	InternalEvent  fn.Option [Event ]
30+ 	InternalEvent  fn.Option [[] Event ]
3131
3232	// ExternalEvent is an optional external event that is to be sent to 
3333	// the daemon for dispatch. Usually, this is some form of I/O. 
@@ -342,9 +342,9 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent( //nolint:funlen
342342	// any preconditions as well as post-send events. 
343343	case  * SendMsgEvent [Event ]:
344344		sendAndCleanUp  :=  func () error  {
345- 			log .Debugf ("FSM(%v): sending message to target(%v ): " + 
345+ 			log .Debugf ("FSM(%v): sending message to target(%x ): " + 
346346				"%v" , s .cfg .Env .Name (),
347- 				daemonEvent .TargetPeer ,
347+ 				daemonEvent .TargetPeer . SerializeCompressed () ,
348348				newLogClosure (func () string  {
349349					return  spew .Sdump (daemonEvent .Msgs )
350350				}),
@@ -481,7 +481,11 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent( //nolint:funlen
481481			defer  s .wg .Done ()
482482			for  {
483483				select  {
484- 				case  spend  :=  <- spendEvent .Spend :
484+ 				case  spend , ok  :=  <- spendEvent .Spend :
485+ 					if  ! ok  {
486+ 						return 
487+ 					}
488+ 
485489					// If there's a post-send event, then 
486490					// we'll send that into the current 
487491					// state now. 
@@ -551,12 +555,6 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent( //nolint:funlen
551555func  (s  * StateMachine [Event , Env ]) applyEvents (currentState  State [Event , Env ],
552556	newEvent  Event ) (State [Event , Env ], error ) {
553557
554- 	log .Debugf ("FSM(%v): applying new event: %v" , s .cfg .Env .Name (),
555- 		newLogClosure (func () string  {
556- 			return  spew .Sdump (newEvent )
557- 		}),
558- 	)
559- 
560558	eventQueue  :=  fn .NewQueue (newEvent )
561559
562560	// Given the next event to handle, we'll process the event, then add 
@@ -614,18 +612,21 @@ func (s *StateMachine[Event, Env]) applyEvents(currentState State[Event, Env],
614612				// our event queue. 
615613				// 
616614				//nolint:lll 
617- 				events .InternalEvent .WhenSome (func (inEvent  Event ) {
618- 					log .Debugf ("FSM(%v): adding new " + 
619- 						"internal event to queue: %v" ,
620- 						s .cfg .Env .Name (),
621- 						newLogClosure (func () string  {
622- 							return  spew .Sdump (
623- 								inEvent ,
624- 							)
625- 						}),
626- 					)
615+ 				events .InternalEvent .WhenSome (func (es  []Event ) {
616+ 					for  _ , inEvent  :=  range  es  {
617+ 						log .Debugf ("FSM(%v): adding " + 
618+ 							"new internal event " + 
619+ 							"to queue: %v" ,
620+ 							s .cfg .Env .Name (),
621+ 							newLogClosure (func () string  { //nolint:lll 
622+ 								return  spew .Sdump (
623+ 									inEvent ,
624+ 								)
625+ 							}),
626+ 						)
627627
628- 					eventQueue .Enqueue (inEvent )
628+ 						eventQueue .Enqueue (inEvent )
629+ 					}
629630				})
630631
631632				return  nil 
0 commit comments