diff --git a/common/sched_queue.go b/common/sched_queue.go index e5ed0667..7e7c9f44 100644 --- a/common/sched_queue.go +++ b/common/sched_queue.go @@ -142,3 +142,15 @@ func (cq *SchedQueue) durationUntilNext(now time.Time) time.Duration { } return time.Duration(math.MaxInt64) } + +// ensure that the background goroutine has executed any pending callbacks +func (cq *SchedQueue) Flush() { + ch := make(chan struct{}) + flushFunc := func() time.Time { + atomic.AddUint64(&cq.counter, ^uint64(0)) // decrement so nobody sees this + close(ch) + return time.Time{} + } + cq.schedChan <- &schedCall{c: flushFunc, t: time.Time{}} + <-ch +}