forked from thatguystone/cog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
50 lines (41 loc) · 940 Bytes
/
error.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
package eio
import (
"fmt"
"sync"
"github.com/iheartradio/cog"
)
// An ErrorProducer only ever returns errors. It's useful for testing error
// handling.
type ErrorProducer struct {
ch chan error
once sync.Once
}
func init() {
RegisterProducer("test_errors",
func(args Args) (Producer, error) {
p := &ErrorProducer{
ch: make(chan error, 1),
}
return p, nil
})
}
// Produce implements Producer.Produce
func (p *ErrorProducer) Produce([]byte) {
p.ch <- fmt.Errorf("i only produce errors")
}
// Rotate implements Producer.Rotate
func (*ErrorProducer) Rotate() error {
return fmt.Errorf("i refuse to be told to rotate things")
}
// Errs implements Producer.Errs
func (p *ErrorProducer) Errs() <-chan error {
return p.ch
}
// Close implements Producer.Close
func (p *ErrorProducer) Close() (errs cog.Errors) {
p.once.Do(func() {
close(p.ch)
errs.Add(fmt.Errorf("yeah, that close failed"))
})
return
}