mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 04:54:05 -05:00
* Add log capitalization analyzer and apply fixes across codebase Implements a new nogo analyzer to enforce proper log message capitalization and applies the fixes to all affected log statements throughout the beacon chain, validator, and supporting components. Co-Authored-By: Claude <noreply@anthropic.com> * Radek's feedback --------- Co-authored-by: Claude <noreply@anthropic.com>
32 lines
820 B
Go
32 lines
820 B
Go
// Package async includes helpers for scheduling runnable, periodic functions and contains useful helpers for converting multi-processor computation.
|
|
package async
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"runtime"
|
|
"time"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// RunEvery runs the provided command periodically.
|
|
// It runs in a goroutine, and can be cancelled by finishing the supplied context.
|
|
func RunEvery(ctx context.Context, period time.Duration, f func()) {
|
|
funcName := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
|
|
ticker := time.NewTicker(period)
|
|
go func() {
|
|
for {
|
|
select {
|
|
case <-ticker.C:
|
|
log.WithField("function", funcName).Trace("Running")
|
|
f()
|
|
case <-ctx.Done():
|
|
log.WithField("function", funcName).Debug("Context is closed, exiting")
|
|
ticker.Stop()
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
}
|