-
Notifications
You must be signed in to change notification settings - Fork 0
/
websockets.go
42 lines (38 loc) · 983 Bytes
/
websockets.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
// Package websockets implements functionality related to the API websockets.
package websockets
import (
"github.com/jmoiron/sqlx"
"gopkg.in/redis.v5"
)
var (
red *redis.Client
db *sqlx.DB
)
// Start begins websocket functionality
func Start(r *redis.Client, _db *sqlx.DB) error {
red = r
db = _db
go scoreRetriever()
go matchRetriever()
return nil
}
func cleanup(connID uint64) {
scoreSubscriptionsMtx.Lock()
for idx, el := range scoreSubscriptions {
if el.Conn.ID == connID {
scoreSubscriptions[idx] = scoreSubscriptions[len(scoreSubscriptions)-1]
scoreSubscriptions = scoreSubscriptions[:len(scoreSubscriptions)-1]
break
}
}
scoreSubscriptionsMtx.Unlock()
multiSubscriptionsMtx.Lock()
for idx, el := range multiSubscriptions {
if el.ID == connID {
multiSubscriptions[idx] = multiSubscriptions[len(multiSubscriptions)-1]
multiSubscriptions = multiSubscriptions[:len(multiSubscriptions)-1]
break
}
}
multiSubscriptionsMtx.Unlock()
}