]>
Commit | Line | Data |
---|---|---|
bae9f6d2 JC |
1 | package yamux |
2 | ||
107c1cdb ND |
3 | import ( |
4 | "sync" | |
5 | "time" | |
6 | ) | |
7 | ||
8 | var ( | |
9 | timerPool = &sync.Pool{ | |
10 | New: func() interface{} { | |
11 | timer := time.NewTimer(time.Hour * 1e6) | |
12 | timer.Stop() | |
13 | return timer | |
14 | }, | |
15 | } | |
16 | ) | |
17 | ||
bae9f6d2 JC |
18 | // asyncSendErr is used to try an async send of an error |
19 | func asyncSendErr(ch chan error, err error) { | |
20 | if ch == nil { | |
21 | return | |
22 | } | |
23 | select { | |
24 | case ch <- err: | |
25 | default: | |
26 | } | |
27 | } | |
28 | ||
29 | // asyncNotify is used to signal a waiting goroutine | |
30 | func asyncNotify(ch chan struct{}) { | |
31 | select { | |
32 | case ch <- struct{}{}: | |
33 | default: | |
34 | } | |
35 | } | |
36 | ||
37 | // min computes the minimum of two values | |
38 | func min(a, b uint32) uint32 { | |
39 | if a < b { | |
40 | return a | |
41 | } | |
42 | return b | |
43 | } |