mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 13:02:33 +02:00
fix panic close on closed channel
This commit is contained in:
parent
7e60d1803c
commit
65afc73f25
1 changed files with 9 additions and 8 deletions
|
@ -3,7 +3,6 @@ package task
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -20,17 +19,19 @@ func (t *Task) addCallback(about string, fn func(), waitSubTasks bool) {
|
|||
}
|
||||
|
||||
func (t *Task) addChildCount() {
|
||||
if atomic.AddUint32(&t.children, 1) == 1 {
|
||||
t.mu.Lock()
|
||||
if t.childrenDone == nil {
|
||||
t.childrenDone = make(chan struct{})
|
||||
}
|
||||
t.mu.Unlock()
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
t.children++
|
||||
if t.children == 1 {
|
||||
t.childrenDone = make(chan struct{})
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Task) subChildCount() {
|
||||
switch atomic.AddUint32(&t.children, ^uint32(0)) {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
t.children--
|
||||
switch t.children {
|
||||
case 0:
|
||||
close(t.childrenDone)
|
||||
case ^uint32(0):
|
||||
|
|
Loading…
Add table
Reference in a new issue