Code Review: Last replacement wins.

This commit is contained in:
Matt T. Proud 2013-06-05 16:29:05 +02:00
parent 9cde48754b
commit d4db3cf00b

View file

@ -26,7 +26,7 @@ const (
intervalKey = "interval"
targetAddQueueSize = 100
targetReplaceQueueSize = 100
targetReplaceQueueSize = 1
)
type TargetPool struct {
@ -82,7 +82,16 @@ func (p *TargetPool) addTarget(target Target) {
}
func (p *TargetPool) ReplaceTargets(newTargets []Target) {
p.replaceTargetsQueue <- newTargets
p.Lock()
defer p.Unlock()
// If there is anything remaining in the queue for effectuation, clear it out,
// because the last mutation should win.
select {
case <-p.replaceTargetsQueue:
default:
p.replaceTargetsQueue <- newTargets
}
}
func (p *TargetPool) replaceTargets(newTargets []Target) {