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

Commit c2a62a2

Browse files
authored
fix: Add function to stop the defaultWorker (#1272)
* fix: Add function to stop the defaultWorker * Close channels on stop to prevent blockage on multiple Stop() calls
1 parent bf52d9d commit c2a62a2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

stats/view/worker.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ func SetReportingPeriod(d time.Duration) {
232232
defaultWorker.SetReportingPeriod(d)
233233
}
234234

235+
// Stop stops the default worker.
236+
func Stop() {
237+
defaultWorker.Stop()
238+
}
239+
235240
// SetReportingPeriod sets the interval between reporting aggregated views in
236241
// the program. If duration is less than or equal to zero, it enables the
237242
// default behavior.
@@ -292,7 +297,7 @@ func (w *worker) start() {
292297
case <-w.quit:
293298
w.timer.Stop()
294299
close(w.c)
295-
w.done <- true
300+
close(w.done)
296301
return
297302
}
298303
}
@@ -301,8 +306,11 @@ func (w *worker) start() {
301306
func (w *worker) Stop() {
302307
prodMgr := metricproducer.GlobalManager()
303308
prodMgr.DeleteProducer(w)
304-
305-
w.quit <- true
309+
select {
310+
case <-w.quit:
311+
default:
312+
close(w.quit)
313+
}
306314
<-w.done
307315
}
308316

0 commit comments

Comments
 (0)