mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-04-25 20:58:04 +08:00
29 lines
402 B
Go
29 lines
402 B
Go
package util
|
|
|
|
import (
|
|
"context"
|
|
"runtime/debug"
|
|
"time"
|
|
|
|
"github.com/metacubex/mihomo/log"
|
|
)
|
|
|
|
func StartRoutine(ctx context.Context, d time.Duration, f func()) {
|
|
go func() {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
log.Errorln("[BUG] %v %s", r, string(debug.Stack()))
|
|
}
|
|
}()
|
|
for {
|
|
time.Sleep(d)
|
|
f()
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
default:
|
|
}
|
|
}
|
|
}()
|
|
}
|