Chore: health checks return immediately if completed (#1097)

This commit is contained in:
Kr328 2020-11-24 22:52:23 +08:00 committed by GitHub
parent 994cbff215
commit 0d33dc3eb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ package provider
import ( import (
"context" "context"
"sync"
"time" "time"
C "github.com/Dreamacro/clash/constant" C "github.com/Dreamacro/clash/constant"
@ -59,11 +60,18 @@ func (hc *HealthCheck) touch() {
func (hc *HealthCheck) check() { func (hc *HealthCheck) check() {
ctx, cancel := context.WithTimeout(context.Background(), defaultURLTestTimeout) ctx, cancel := context.WithTimeout(context.Background(), defaultURLTestTimeout)
wg := &sync.WaitGroup{}
for _, proxy := range hc.proxies { 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() cancel()
} }