infra/op-conductor-mon/pkg/monitor/scheduler.go

23 lines
315 B
Go
Raw Normal View History

package monitor
import (
"context"
"time"
)
func schedule(ctx context.Context, interval time.Duration, handler func(ctx context.Context)) {
go func() {
for {
timer := time.NewTimer(interval)
handler(ctx)
select {
case <-timer.C:
case <-ctx.Done():
timer.Stop()
return
}
}
}()
}