-
Notifications
You must be signed in to change notification settings - Fork 12
/
session_change_lists.go
66 lines (57 loc) · 1.88 KB
/
session_change_lists.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
60
61
62
63
64
65
66
package enigma
import (
"sync"
)
type (
sessionChangeLists struct {
mutex sync.Mutex
channels map[*sessionChangeListEntry]bool
}
sessionChangeListEntry struct {
pushedOnly bool
channel chan ChangeLists
}
)
func (e *sessionChangeLists) emitChangeLists(changed, closed, suspended []int, pushed bool) {
if len(changed) > 0 || len(closed) > 0 {
e.mutex.Lock()
defer e.mutex.Unlock()
for channelEntry := range e.channels {
if pushed || !channelEntry.pushedOnly {
channelEntry.channel <- ChangeLists{Changed: changed, Closed: closed, Suspended: suspended}
}
}
}
}
// ChangeListsChannel returns a channel that receives change and close notifications from Qlik Associative Engine. if the pushedOnly argument is set to true
// only pushed change lists are put into the channel - not changes that are returned as a response to an API call.
func (e *sessionChangeLists) ChangeListsChannel(pushedOnly bool) chan ChangeLists {
e.mutex.Lock()
defer e.mutex.Unlock()
channelEntry := &sessionChangeListEntry{channel: make(chan ChangeLists, 16), pushedOnly: pushedOnly}
e.channels[channelEntry] = true
return channelEntry.channel
}
// CloseChangeListsChannel closes and unregisters the supplied event channel from the session.
func (e *sessionChangeLists) CloseChangeListsChannel(channel chan ChangeLists) {
e.mutex.Lock()
defer e.mutex.Unlock()
for channelEntry := range e.channels {
if channelEntry.channel == channel {
close(channelEntry.channel)
delete(e.channels, channelEntry)
break
}
}
}
func (e *sessionChangeLists) closeAllChangeListChannels() {
e.mutex.Lock()
defer e.mutex.Unlock()
for channelEntry := range e.channels {
close(channelEntry.channel)
}
e.channels = make(map[*sessionChangeListEntry]bool)
}
func newSessionChangeLists() *sessionChangeLists {
return &sessionChangeLists{channels: make(map[*sessionChangeListEntry]bool), mutex: sync.Mutex{}}
}