MCPcopy
hub / github.com/zu1k/proxypool / CleanBadProxiesWithGrpool

Function CleanBadProxiesWithGrpool

pkg/proxy/check.go:41–89  ·  view source on GitHub ↗
(proxies []Proxy)

Source from the content-addressed store, hash-verified

39}
40
41func CleanBadProxiesWithGrpool(proxies []Proxy) (cproxies []Proxy) {
42 pool := grpool.NewPool(500, 200)
43
44 c := make(chan checkResult)
45 defer close(c)
46
47 pool.WaitCount(len(proxies))
48 go func() {
49 for _, p := range proxies {
50 pp := p
51 pool.JobQueue <- func() {
52 defer pool.JobDone()
53 delay, err := testDelay(pp)
54 if err == nil {
55 c <- checkResult{
56 name: pp.Identifier(),
57 delay: delay,
58 }
59 }
60 }
61 }
62 }()
63 done := make(chan struct{})
64 defer close(done)
65
66 go func() {
67 pool.WaitAll()
68 pool.Release()
69 done <- struct{}{}
70 }()
71
72 okMap := make(map[string]struct{})
73 for {
74 select {
75 case r := <-c:
76 if r.delay > 0 {
77 okMap[r.name] = struct{}{}
78 }
79 case <-done:
80 cproxies = make(ProxyList, 0, 500)
81 for _, p := range proxies {
82 if _, ok := okMap[p.Identifier()]; ok {
83 cproxies = append(cproxies, p.Clone())
84 }
85 }
86 return
87 }
88 }
89}
90
91func CleanBadProxies(proxies []Proxy) (cproxies []Proxy) {
92 c := make(chan checkResult, 40)

Callers 1

CrawlGoFunction · 0.92

Calls 3

testDelayFunction · 0.85
IdentifierMethod · 0.65
CloneMethod · 0.65

Tested by

no test coverage detected