-
Notifications
You must be signed in to change notification settings - Fork 8
/
pipeline_tree_verifier.go
61 lines (51 loc) · 1.22 KB
/
pipeline_tree_verifier.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
51
52
53
54
55
56
57
58
59
60
61
//go:build !tinywasm
package gtree
import (
"context"
"sync"
)
type defaultVerifierPipeline struct {
*defaultVerifierSimple
}
func newVerifierPipeline(dir string, strict bool) verifierPipeline {
return &defaultVerifierPipeline{
defaultVerifierSimple: newVerifierSimple(dir, strict).(*defaultVerifierSimple),
}
}
const workerVerifyNum = 10
func (dv *defaultVerifierPipeline) verify(ctx context.Context, roots <-chan *Node) <-chan error {
errc := make(chan error, 1)
go func() {
defer func() {
close(errc)
}()
wg := &sync.WaitGroup{}
for i := 0; i < workerVerifyNum; i++ {
wg.Add(1)
go dv.worker(ctx, wg, roots, errc)
}
wg.Wait()
}()
return errc
}
func (dv *defaultVerifierPipeline) worker(ctx context.Context, wg *sync.WaitGroup, roots <-chan *Node, errc chan<- error) {
defer wg.Done()
for {
select {
case <-ctx.Done():
return
case root, ok := <-roots:
if !ok {
return
}
extra, noExists, err := dv.verifyRoot(root)
if err != nil {
errc <- err
}
// TODO: 1Root分のエラーしか出力しないようになってるから、全Root分の検査結果を出力する方がいいかも
if err := dv.handleErr(extra, noExists); err != nil {
errc <- err
}
}
}
}