mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-26 16:57:08 +00:00
chore: rebuild slowdown code
This commit is contained in:
@@ -11,12 +11,11 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/jpillora/backoff"
|
||||
|
||||
N "github.com/metacubex/mihomo/common/net"
|
||||
"github.com/metacubex/mihomo/component/nat"
|
||||
P "github.com/metacubex/mihomo/component/process"
|
||||
"github.com/metacubex/mihomo/component/resolver"
|
||||
"github.com/metacubex/mihomo/component/slowdown"
|
||||
"github.com/metacubex/mihomo/component/sniffer"
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
"github.com/metacubex/mihomo/constant/features"
|
||||
@@ -699,12 +698,7 @@ func shouldStopRetry(err error) bool {
|
||||
}
|
||||
|
||||
func retry[T any](ctx context.Context, ft func(context.Context) (T, error), fe func(err error)) (t T, err error) {
|
||||
b := &backoff.Backoff{
|
||||
Min: 10 * time.Millisecond,
|
||||
Max: 1 * time.Second,
|
||||
Factor: 2,
|
||||
Jitter: true,
|
||||
}
|
||||
s := slowdown.New()
|
||||
for i := 0; i < 10; i++ {
|
||||
t, err = ft(ctx)
|
||||
if err != nil {
|
||||
@@ -714,10 +708,9 @@ func retry[T any](ctx context.Context, ft func(context.Context) (T, error), fe f
|
||||
if shouldStopRetry(err) {
|
||||
return
|
||||
}
|
||||
select {
|
||||
case <-time.After(b.Duration()):
|
||||
if s.Wait(ctx) == nil {
|
||||
continue
|
||||
case <-ctx.Done():
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user