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

fix: Add function to stop the defaultWorker #1272

Merged
merged 2 commits into from Feb 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions stats/view/worker.go
Expand Up @@ -221,6 +221,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 @@ -281,7 +286,7 @@ func (w *worker) start() {
case <-w.quit:
w.timer.Stop()
close(w.c)
w.done <- true
close(w.done)
return
}
}
Expand All @@ -290,8 +295,11 @@ func (w *worker) start() {
func (w *worker) Stop() {
prodMgr := metricproducer.GlobalManager()
prodMgr.DeleteProducer(w)

w.quit <- true
select {
dashpole marked this conversation as resolved.
Show resolved Hide resolved
case <-w.quit:
default:
close(w.quit)
}
<-w.done
}

Expand Down