Fix validator bugs

This commit is contained in:
Kevin Cotugno 2017-10-19 21:55:42 -07:00
parent 84c99ff732
commit a5e78e3814

View File

@ -20,16 +20,14 @@ type Validator struct {
Products []string Products []string
done chan struct{} done chan struct{}
stopped bool
dirty bool dirty bool
} }
func (v *Validator) Stop() { func (v *Validator) Stop() {
if v.done != nil { if v.done != nil && !v.stopped {
select { v.done <- struct{}{}
case v.done <- struct{}{}: v.stopped = true
default:
}
} }
} }
@ -52,6 +50,7 @@ func (v *Validator) Start(frequency time.Duration) {
for !done { for !done {
select { select {
case <-v.done: case <-v.done:
v.Logger.Info("Done")
done = true done = true
ticker.Stop() ticker.Stop()
case <-ticker.C: case <-ticker.C:
@ -81,7 +80,6 @@ func (v *Validator) emitProducts(done chan struct{}) {
} }
}() }()
} }
func (v *Validator) validateProduct(product string) { func (v *Validator) validateProduct(product string) {