Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ func (e *Engine) GoTick(ticker *timeutil.Ticker, fn func(context.Context)) {
})
}

// GoTickUntil is like GoTick but halts when fn returns true, and closes the returned chan.
func (e *Engine) GoTickUntil(ticker *timeutil.Ticker, fn func(context.Context) bool) <-chan struct{} {
ch := make(chan struct{})
e.Go(func(ctx context.Context) {
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
if fn(ctx) {
close(ch)
return
}
}
}
})
return ch
}

// Tracer returns the otel tracer with service attributes included.
func (e *Engine) Tracer() trace.Tracer {
return e.tracer
Expand Down
Loading