Chore: health checks return immediately if completed (#1097)
This commit is contained in:
parent
994cbff215
commit
0d33dc3eb9
1 changed files with 10 additions and 2 deletions
|
@ -2,6 +2,7 @@ package provider
|
|||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
|
@ -59,11 +60,18 @@ func (hc *HealthCheck) touch() {
|
|||
|
||||
func (hc *HealthCheck) check() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), defaultURLTestTimeout)
|
||||
wg := &sync.WaitGroup{}
|
||||
|
||||
for _, proxy := range hc.proxies {
|
||||
go proxy.URLTest(ctx, hc.url)
|
||||
wg.Add(1)
|
||||
|
||||
go func(p C.Proxy) {
|
||||
p.URLTest(ctx, hc.url)
|
||||
wg.Done()
|
||||
}(proxy)
|
||||
}
|
||||
|
||||
<-ctx.Done()
|
||||
wg.Wait()
|
||||
cancel()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue