-
Notifications
You must be signed in to change notification settings - Fork 3
/
manager_close.go
100 lines (86 loc) · 1.83 KB
/
manager_close.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package pushKit
import (
"github.com/richelieu-yang/chimera/v3/src/core/strKit"
)
func CloseAll(reason string) {
reason = polyfillCloseReason(reason)
/* 读锁 */
idMap.RLockFunc(func() {
for _, channel := range idMap.Map {
_ = channel.Close(reason)
}
})
return
}
// CloseById
/*
PS: 解绑(unbind)后续由 inner handler 处理.
*/
func CloseById(id string, reason string) (err error) {
reason = polyfillCloseReason(reason)
/* 读锁 */
idMap.RLockFunc(func() {
channel := idMap.Map[id]
if channel == nil {
return
}
err = channel.Close(reason)
})
return
}
// CloseByBsid
/*
PS: 解绑(unbind)后续由 inner handler 处理.
*/
func CloseByBsid(bsid string, reason string) (err error) {
reason = polyfillCloseReason(reason)
/* 读锁 */
bsidMap.RLockFunc(func() {
channel := bsidMap.Map[bsid]
if channel == nil {
return
}
err = channel.Close(reason)
// 解绑(unbind)后续由 inner handler 处理
})
return
}
// CloseByUser
/*
PS: 解绑(unbind)后续由 inner handler 处理.
*/
func CloseByUser(user string, reason string) {
reason = polyfillCloseReason(reason)
/* 读锁 */
userMap.RLockFunc(func() {
userSet := userMap.Map[user]
/* 读锁 */
userSet.RLockFunc(func() {
userSet.Set.Each(func(channel Channel) bool {
_ = channel.Close(reason)
return false
})
})
})
}
// CloseByGroup
/*
PS: 解绑(unbind)后续由 inner handler 处理.
*/
func CloseByGroup(group string, reason string) {
reason = polyfillCloseReason(reason)
/* 读锁 */
groupMap.RLockFunc(func() {
groupSet := groupMap.Map[group]
/* 读锁 */
groupSet.RLockFunc(func() {
groupSet.Set.Each(func(channel Channel) bool {
_ = channel.Close(reason)
return false
})
})
})
}
func polyfillCloseReason(reason string) string {
return strKit.EmptyToDefault(reason, "no reason")
}