forked from git-lfs/git-lfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannels.go
36 lines (29 loc) · 909 Bytes
/
channels.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
package tools
import "fmt"
// Interface for all types of wrapper around a channel of results and an error channel
// Implementors will expose a type-specific channel for results
// Call the Wait() function after processing the results channel to catch any errors
// that occurred during the async processing
type ChannelWrapper interface {
// Call this after processing results channel to check for async errors
Wait() error
}
// Base implementation of channel wrapper to just deal with errors
type BaseChannelWrapper struct {
errorChan <-chan error
}
func (w *BaseChannelWrapper) Wait() error {
var err error
for e := range w.errorChan {
if err != nil {
// Combine in case multiple errors
err = fmt.Errorf("%v\n%v", err, e)
} else {
err = e
}
}
return err
}
func NewBaseChannelWrapper(errChan <-chan error) *BaseChannelWrapper {
return &BaseChannelWrapper{errorChan: errChan}
}