Add a Flush() routine to synchronize callers

This commit is contained in:
Bryan Boreham committed 2015-06-15 13:48:24 +01:00
1 parent 2b7fb699af
commit e49a29197b
1 file changed
+12
+12
View File
@@ -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
}