MCPcopy Create free account
hub / github.com/chainreactors/spray / Run

Method Run

core/pool/checkpool.go:58–114  ·  view source on GitHub ↗
(ctx context.Context, offset, limit int)

Source from the content-addressed store, hash-verified

56}
57
58func (pool *CheckPool) Run(ctx context.Context, offset, limit int) {
59 pool.Worder.Run()
60
61 worderCh := pool.Worder.Output
62 var allDone <-chan struct{}
63
64 var drainOnce sync.Once
65 startDrain := func() {
66 drainOnce.Do(func() {
67 worderCh = nil
68 ch := make(chan struct{})
69 go func() { pool.wg.Wait(); close(ch) }()
70 allDone = ch
71 })
72 }
73
74Loop:
75 for {
76 select {
77 case u, ok := <-worderCh:
78 if !ok {
79 startDrain()
80 continue
81 }
82
83 if pool.reqCount.Load() < int64(offset) {
84 pool.reqCount.Add(1)
85 continue
86 }
87
88 if pool.reqCount.Load() > int64(limit) {
89 startDrain()
90 continue
91 }
92
93 pool.wg.Add(1)
94 if err := pool.Pool.Invoke(newUnit(u, parsers.CheckSource)); err != nil {
95 pool.wg.Done()
96 }
97 case u, ok := <-pool.additionCh:
98 if !ok {
99 continue
100 }
101 if err := pool.Pool.Invoke(u); err != nil {
102 pool.wg.Done()
103 }
104 case <-allDone:
105 break Loop
106 case <-ctx.Done():
107 break Loop
108 case <-pool.ctx.Done():
109 break Loop
110 }
111 }
112
113 pool.Close()
114}
115func (pool *CheckPool) Close() {

Callers 1

RunWithCheckMethod · 0.95

Calls 5

CloseMethod · 0.95
newUnitFunction · 0.85
DoMethod · 0.80
InvokeMethod · 0.80
DoneMethod · 0.45

Tested by

no test coverage detected