forked from vladimirvivien/automi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
null.go
48 lines (40 loc) · 861 Bytes
/
null.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
package collectors
import (
"context"
"github.com/vladimirvivien/automi/api"
autoctx "github.com/vladimirvivien/automi/api/context"
"github.com/vladimirvivien/automi/util"
)
type NullCollector struct {
input <-chan interface{}
logf api.LogFunc
}
func Null() *NullCollector {
return new(NullCollector)
}
func (s *NullCollector) SetInput(in <-chan interface{}) {
s.input = in
}
// Open opens the node to start collecting
func (s *NullCollector) Open(ctx context.Context) <-chan error {
result := make(chan error)
s.logf = autoctx.GetLogFunc(ctx)
util.Logfn(s.logf, "Opening null collector")
go func() {
defer func() {
util.Logfn(s.logf, "Closing null collector")
close(result)
}()
for {
select {
case _, opened := <-s.input:
if !opened {
return
}
case <-ctx.Done():
return
}
}
}()
return result
}