Add a Flush() routine to synchronize callers
This commit is contained in:
1 parent
2b7fb699af
commit
e49a29197b
1 file changed
+12
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user