diff --git a/workers/supervisor.go b/workers/supervisor.go index c1c1640..14ad604 100644 --- a/workers/supervisor.go +++ b/workers/supervisor.go @@ -50,6 +50,10 @@ func (s *supervisor) loop() { end = true s.pool.stop() } + case "0": + if !end { + s.poolSize = 0 + } case "-1": if !end && s.poolSize > 0 { s.poolSize-- @@ -88,6 +92,10 @@ func (s *supervisor) stopOneWorker() { s.eventCh <- "-1" } +func (s *supervisor) stopAllWorkers() { + s.eventCh <- "0" +} + func (s *supervisor) stop() { s.eventCh <- "stop" diff --git a/workers/workers.go b/workers/workers.go index bb04a77..d3af822 100644 --- a/workers/workers.go +++ b/workers/workers.go @@ -23,6 +23,10 @@ func (ws *Workers) StopOneWorker() { ws.supervisor.stopOneWorker() } +func (ws *Workers) StopAllWorkers() { + ws.supervisor.stopAllWorkers() +} + func (ws *Workers) State() map[string]*Worker { return ws.state.data() }