forked from google/gxui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channeled_event.go
50 lines (43 loc) · 972 Bytes
/
channeled_event.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
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gxui
import (
"reflect"
"sync"
)
type ChanneledEvent struct {
sync.RWMutex
base EventBase
channel chan func()
}
func CreateChanneledEvent(signature interface{}, channel chan func()) Event {
e := &ChanneledEvent{
channel: channel,
}
e.base.init(signature)
baseUnlisten := e.base.unlisten
e.base.unlisten = func(id int) {
e.RLock()
baseUnlisten(id)
e.RUnlock()
}
return e
}
func (e *ChanneledEvent) Fire(args ...interface{}) {
e.base.VerifyArguments(args)
e.channel <- func() {
e.RLock()
e.base.InvokeListeners(args)
e.RUnlock()
}
}
func (e *ChanneledEvent) Listen(listener interface{}) EventSubscription {
e.Lock()
res := e.base.Listen(listener)
e.Unlock()
return res
}
func (e *ChanneledEvent) ParameterTypes() []reflect.Type {
return e.base.ParameterTypes()
}