Browse Source

En cours de développement

master
losyme 7 months ago
parent
commit
794fa1889a
  1. 14
      workers/worker.go

14
workers/worker.go

@ -7,6 +7,7 @@
package workers
import (
"sync"
"time"
"forge.chapril.org/losyme/uuid"
@ -18,7 +19,8 @@ type worker struct {
runner Runner
dashboard *dashboard
logger Logger
stopCh chan bool
stopCh chan struct{}
closeOnce sync.Once
}
func newWorker(hostname string, runner Runner, dashboard *dashboard, logger Logger) (*worker, error) {
@ -35,7 +37,7 @@ func newWorker(hostname string, runner Runner, dashboard *dashboard, logger Logg
runner: runner,
dashboard: dashboard,
logger: logger,
stopCh: make(chan bool),
stopCh: make(chan struct{}),
}
return w, nil
@ -59,7 +61,7 @@ func (w *worker) loop() {
<-timer.C
}
close(w.stopCh)
w.stop() // close
}()
for {
@ -91,7 +93,11 @@ func (w *worker) start(stoppedCh chan<- string) {
}
func (w *worker) stop() {
w.stopCh <- true
w.closeOnce.Do(
func() {
close(w.stopCh)
},
)
}
/*

Loading…
Cancel
Save