-
Notifications
You must be signed in to change notification settings - Fork 10
/
constants.go
90 lines (76 loc) · 1.93 KB
/
constants.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
package phx
import (
"time"
)
const (
// defaultConnectTimeout is the default handshake timeout
defaultConnectTimeout = 10 * time.Second
// defaultPushTimeout is the default timeout when waiting for a reply from a pushed message
defaultPushTimeout = 10 * time.Second
// defaultHeartbeatInterval is the default time between heartbeats
defaultHeartbeatInterval = 30 * time.Second
// busyWait is the time for goroutines to sleep while waiting. Lower = more CPU. Higher = less responsive
busyWait = 100 * time.Millisecond
// messageQueueLength is the number of messages to queue when not connected before blocking
messageQueueLength = 1000
)
func defaultReconnectAfterFunc(tries int) time.Duration {
schedule := []time.Duration{10, 50, 100, 150, 200, 250, 500, 1000, 2000}
if tries >= 1 && tries-1 < len(schedule) {
return schedule[tries-1] * time.Millisecond
} else {
return 5000 * time.Millisecond
}
}
func defaultRejoinAfterFunc(tries int) time.Duration {
schedule := []time.Duration{1000, 2000, 5000}
if tries >= 1 && tries-1 < len(schedule) {
return schedule[tries-1] * time.Millisecond
} else {
return 10000 * time.Millisecond
}
}
type ConnectionState int
const (
ConnectionConnecting ConnectionState = iota
ConnectionOpen
ConnectionClosing
ConnectionClosed
)
func (s ConnectionState) String() string {
switch s {
case ConnectionConnecting:
return "connecting"
case ConnectionOpen:
return "open"
case ConnectionClosing:
return "closing"
case ConnectionClosed:
return "closed"
}
return "unknown"
}
type ChannelState int
const (
ChannelClosed ChannelState = iota
ChannelErrored
ChannelJoined
ChannelJoining
ChannelLeaving
ChannelRemoved
)
func (c ChannelState) String() string {
switch c {
case ChannelClosed:
return "closed"
case ChannelErrored:
return "errored"
case ChannelJoined:
return "joined"
case ChannelJoining:
return "joining"
case ChannelLeaving:
return "leaving"
}
return "unknown"
}