diff --git a/config/node.go b/config/node.go index d6d4d56..fbc8ccc 100644 --- a/config/node.go +++ b/config/node.go @@ -9,6 +9,7 @@ import ( "github.com/fufuok/utils" "github.com/fufuok/utils/myip" + "github.com/fufuok/utils/pools/timerpool" "github.com/imroc/req/v3" "github.com/fufuok/pkg/json" @@ -182,10 +183,12 @@ func GetNodeIPFromAPIs(ipapi string, timeout ...time.Duration) string { }() } + timer := timerpool.New(dur) + defer timerpool.Release(timer) select { case ip := <-ipChan: return ip - case <-time.After(dur): + case <-timer.C: } return "" } diff --git a/master/ntpdate.go b/master/ntpdate.go index 4125625..15b0161 100644 --- a/master/ntpdate.go +++ b/master/ntpdate.go @@ -5,6 +5,7 @@ import ( "time" "github.com/fufuok/ntp" + "github.com/fufuok/utils/pools/timerpool" "github.com/fufuok/pkg/common" "github.com/fufuok/pkg/config" @@ -21,8 +22,10 @@ var ( // WaitUntilNtpdate 等待, 直到第一次时间同步成功 func WaitUntilNtpdate(timeout time.Duration) bool { + timer := timerpool.New(timeout) + defer timerpool.Release(timer) select { - case <-time.After(timeout): + case <-timer.C: return false case <-ntpFirstDoneChan: return true