-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (44 loc) · 999 Bytes
/
main.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"sync"
"github.com/dsinecos/go-event-emitter/evtemtr"
)
type button struct {
buttonType string
*evtemtr.EventEmitter
}
// ButtonEvent TODO
type ButtonEvent struct {
string
}
// GetEventName TODO
func (be ButtonEvent) GetEventName() string {
return be.string
}
func main() {
button := button{
"light",
evtemtr.New(),
}
onMouseOver := make(chan evtemtr.EventTuple)
onceMouseOver := make(chan evtemtr.EventTuple)
mouseOverButtonEvent := ButtonEvent{"mouseover"}
var wg sync.WaitGroup
button.On(mouseOverButtonEvent, onMouseOver).List()
wg.Add(1)
listen(onMouseOver, &wg)
button.Once(mouseOverButtonEvent, onceMouseOver).List()
// wg.Add(1)
// listen(onceMouseOver, &wg)
button.Remove(mouseOverButtonEvent, onceMouseOver).List()
button.Emit(mouseOverButtonEvent, 2)
wg.Wait()
button.List()
}
func listen(c <-chan evtemtr.EventTuple, wg *sync.WaitGroup) {
go func() {
defer wg.Done()
fmt.Println("Listener invoked ", <-c)
}()
}