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 (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,17 +19,19 @@ func (t *Task) addCallback(about string, fn func(), waitSubTasks bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) addChildCount() {
|
func (t *Task) addChildCount() {
|
||||||
if atomic.AddUint32(&t.children, 1) == 1 {
|
t.mu.Lock()
|
||||||
t.mu.Lock()
|
defer t.mu.Unlock()
|
||||||
if t.childrenDone == nil {
|
t.children++
|
||||||
t.childrenDone = make(chan struct{})
|
if t.children == 1 {
|
||||||
}
|
t.childrenDone = make(chan struct{})
|
||||||
t.mu.Unlock()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) subChildCount() {
|
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:
|
case 0:
|
||||||
close(t.childrenDone)
|
close(t.childrenDone)
|
||||||
case ^uint32(0):
|
case ^uint32(0):
|
||||||
|
|
Loading…
Add table
Reference in a new issue