1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package event
- type System struct {
- busList []*eventBus
- }
- func NewSystem() *System {
- return &System{[]*eventBus{}}
- }
- // NewBus params are 0 - emitPrefix
- func (s *System) NewBus(params ...string) Bus {
- emitPrefix := ""
- if len(params) != 0 {
- emitPrefix = params[0]
- }
- evtBus := &eventBus{s, emitPrefix, map[string]*[]HandlerFunc{}}
- s.busList = append(s.busList, evtBus)
- return evtBus
- }
- func (s *System) RemoveBus(bus Bus) {
- where := -1
- for i, b := range s.busList {
- if b == bus { // Pointer comparison somehow?
- where = i
- break
- }
- }
- s.busList = append(s.busList[:where], s.busList[where+1:]...)
- }
- func (s *System) handleEvent(evt Event) {
- // Pass this event trough all buses
- for _, bus := range s.busList {
- bus.handleEvent(evt)
- }
- }
|