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
2025-04-16 18:05:26 -07:00
parent 6e6901ec61
commit 1304182897
3 changed files with 175 additions and 12 deletions

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