package lucifer3 import ( "sync/atomic" ) type Service interface { Active() bool HandleEvent(bus *EventBus, event Event) } type ActiveService interface { Service HandleCommand(bus *EventBus, command Command) } type ServiceCommon struct { inactive uint32 } func (s *ServiceCommon) Active() bool { return atomic.LoadUint32(&s.inactive) == 0 } func (s *ServiceCommon) markInactive() { atomic.StoreUint32(&s.inactive, 1) } type callbackService struct { ServiceCommon cb func(event Event) bool } func (c *callbackService) HandleEvent(_ *EventBus, event Event) { if !c.cb(event) { c.markInactive() } } func newCallbackService(cb func(event Event) bool) Service { return &callbackService{ ServiceCommon: ServiceCommon{ inactive: 0, }, cb: cb, } }