protofsm: add new ConfMapper similar to SpendMapper for conf events

In this commit, we add a new ConfMapper which is useful for state
machines that want to project some of the conf attributes into a new
event to be sent post conf.
This commit is contained in:
Olaoluwa Osuntokun committed 2025-06-03 16:27:28 -07:00
1 parent 239aab8b9e
commit cb46f3daa0
3 files changed
+175 -12

No files matched your search

+11 -8
View File
@@ -522,16 +522,19 @@ func (s *StateMachine[Event, Env]) executeDaemonEvent(ctx context.Context,
launched := s.gm.Go(ctx, func(ctx context.Context) {
for {
select {
case <-confEvent.Confirmed:
// If there's a post-conf event, then
//nolint:ll
case conf, ok := <-confEvent.Confirmed:
if !ok {
return
}
// If there's a post-conf mapper, then
// we'll send that into the current
// state now.
//
// TODO(roasbeef): refactor to
// dispatchAfterRecv w/ above
postConf := daemonEvent.PostConfEvent
postConf.WhenSome(func(e Event) {
s.SendEvent(ctx, e)
postConfMapper := daemonEvent.PostConfMapper
postConfMapper.WhenSome(func(f ConfMapper[Event]) {
customEvent := f(conf)
s.SendEvent(ctx, customEvent)
})
return