forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventer.go
36 lines (30 loc) · 798 Bytes
/
eventer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package gobot
type eventer struct {
events map[string]*Event
}
// Eventer is the interface which describes behaviour for a Driver or Adaptor
// which uses events.
type Eventer interface {
// Events returns the Event map.
Events() (events map[string]*Event)
// Event returns an Event by name. Returns nil if the Event is not found.
Event(name string) (event *Event)
// AddEvent adds a new Event given a name.
AddEvent(name string)
}
// NewEventer returns a new Eventer.
func NewEventer() Eventer {
return &eventer{
events: make(map[string]*Event),
}
}
func (e *eventer) Events() map[string]*Event {
return e.events
}
func (e *eventer) Event(name string) (event *Event) {
event, _ = e.events[name]
return
}
func (e *eventer) AddEvent(name string) {
e.events[name] = NewEvent()
}