(proxies []Proxy)
| 39 | } |
| 40 | |
| 41 | func 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 | |
| 91 | func CleanBadProxies(proxies []Proxy) (cproxies []Proxy) { |
| 92 | c := make(chan checkResult, 40) |
no test coverage detected