Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
fix: Add function to stop the defaultWorker (#1272)
Browse files Browse the repository at this point in the history
* fix: Add function to stop the defaultWorker

* Close channels on stop to prevent blockage on multiple Stop() calls
  • Loading branch information
kylecarbs committed Feb 22, 2022
1 parent bf52d9d commit c2a62a2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions stats/view/worker.go
Expand Up @@ -232,6 +232,11 @@ func SetReportingPeriod(d time.Duration) {
defaultWorker.SetReportingPeriod(d)
}

// Stop stops the default worker.
func Stop() {
defaultWorker.Stop()
}

// SetReportingPeriod sets the interval between reporting aggregated views in
// the program. If duration is less than or equal to zero, it enables the
// default behavior.
Expand Down Expand Up @@ -292,7 +297,7 @@ func (w *worker) start() {
case <-w.quit:
w.timer.Stop()
close(w.c)
w.done <- true
close(w.done)
return
}
}
Expand All @@ -301,8 +306,11 @@ func (w *worker) start() {
func (w *worker) Stop() {
prodMgr := metricproducer.GlobalManager()
prodMgr.DeleteProducer(w)

w.quit <- true
select {
case <-w.quit:
default:
close(w.quit)
}
<-w.done
}

Expand Down

0 comments on commit c2a62a2

Please sign in to comment.