prevent resource leak (#1080)

This commit is contained in:
Shu xian 2020-01-03 21:31:47 +08:00 committed by Asim Aslam
parent 4e2339749c
commit 31362bc331

View File

@ -99,6 +99,7 @@ func (t *Task) Run(c task.Command) error {
// subscribe for the pool size
for i := 0; i < t.Options.Pool; i++ {
err := func() error {
// subscribe to work
subWork, err := t.Broker.Subscribe(topic, workFn, broker.Queue(fmt.Sprintf("work.%d", i)))
if err != nil {
@ -107,6 +108,13 @@ func (t *Task) Run(c task.Command) error {
// unsubscribe on completion
defer subWork.Unsubscribe()
return nil
}()
if err != nil {
return err
}
}
// subscribe to all status messages