forked from schwartzmx/gremtune
-
Notifications
You must be signed in to change notification settings - Fork 6
/
channel.go
41 lines (34 loc) · 671 Bytes
/
channel.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
package gremcos
import "sync"
type safeCloseErrorChannel struct {
c chan error
once sync.Once
}
func newSafeCloseErrorChannel(channelBuffer int) *safeCloseErrorChannel {
return &safeCloseErrorChannel{
c: make(chan error, channelBuffer),
}
}
func (c *safeCloseErrorChannel) Close() {
c.once.Do(func() {
if c.c != nil {
close(c.c)
}
})
}
type safeCloseIntChannel struct {
c chan int
once sync.Once
}
func newSafeCloseIntChannel(channelBuffer int) *safeCloseIntChannel {
return &safeCloseIntChannel{
c: make(chan int, channelBuffer),
}
}
func (c *safeCloseIntChannel) Close() {
c.once.Do(func() {
if c.c != nil {
close(c.c)
}
})
}