MCPcopy
hub / github.com/grafana/tempo / doForAtLeast

Function doForAtLeast

tempodb/compactor.go:429–443  ·  view source on GitHub ↗

doForAtLeast executes the function f. It blocks for at least the passed duration but can go longer. if context is cancelled after the function is done we will bail immediately. in the current use case this means that the process is shutting down we don't force f() to cancel, we assume it also respon

(ctx context.Context, dur time.Duration, f func())

Source from the content-addressed store, hash-verified

427// the function is done we will bail immediately. in the current use case this means that the process is shutting down
428// we don't force f() to cancel, we assume it also responds to the cancelled context
429func doForAtLeast(ctx context.Context, dur time.Duration, f func()) {
430 startTime := time.Now()
431 f()
432 elapsed := time.Since(startTime)
433
434 if elapsed < dur {
435 ticker := time.NewTicker(dur - elapsed)
436 defer ticker.Stop()
437
438 select {
439 case <-ticker.C:
440 case <-ctx.Done():
441 }
442 }
443}

Callers 2

compactionLoopMethod · 0.85
TestDoForAtLeastFunction · 0.85

Calls 4

fFunction · 0.85
NowMethod · 0.65
StopMethod · 0.65
DoneMethod · 0.65

Tested by 1

TestDoForAtLeastFunction · 0.68