- close quitChan when Cancel for tasksch.

This commit is contained in:
gazebo
2018-10-21 13:47:53 +08:00
parent 1a9ff7e575
commit 0fb6fe27fe
4 changed files with 31 additions and 25 deletions

View File

@@ -101,8 +101,8 @@ func (t *BaseTask) Init(parallelCount, batchSize int, isContinueWhenError bool,
t.TerminatedAt = utils.DefaultTimeValue
t.TotalItemCount = totalItemCount
t.TotalJobCount = totalJobCount
t.quitChan = make(chan int, parallelCount)
t.finishChan = make(chan int, 2)
t.quitChan = make(chan int, 1)
t.finishChan = make(chan int, 1)
t.Status = TaskStatusWorking
t.C = t.finishChan
@@ -143,9 +143,7 @@ func (t *BaseTask) Cancel() {
t.locker.Lock()
if t.Status < TaskStatusEndBegin && t.Status != TaskStatusCanceling {
t.Status = TaskStatusCanceling
for i := 0; i < t.ParallelCount; i++ {
t.quitChan <- 0
}
close(t.quitChan)
}
t.locker.Unlock()