File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change 23
23
package ants
24
24
25
25
import (
26
+ "log"
26
27
"time"
27
28
)
28
29
@@ -43,26 +44,27 @@ type Worker struct {
43
44
// run starts a goroutine to repeat the process
44
45
// that performs the function calls.
45
46
func (w * Worker ) run () {
47
+ w .pool .incRunning ()
46
48
go func () {
47
49
defer func () {
48
50
if p := recover (); p != nil {
49
51
w .pool .decRunning ()
50
52
if w .pool .PanicHandler != nil {
51
53
w .pool .PanicHandler (p )
52
54
} else {
53
- panic ( p )
55
+ log . Printf ( "worker exits from a panic: %v" , p )
54
56
}
55
57
}
56
58
}()
57
59
58
60
for f := range w .task {
59
61
if f == nil {
60
62
w .pool .decRunning ()
61
- w .pool .cachePool .Put (w )
63
+ w .pool .workerCache .Put (w )
62
64
return
63
65
}
64
66
f ()
65
- w .pool .putWorker (w )
67
+ w .pool .revertWorker (w )
66
68
}
67
69
}()
68
70
}
Original file line number Diff line number Diff line change 23
23
package ants
24
24
25
25
import (
26
+ "log"
26
27
"time"
27
28
)
28
29
@@ -43,26 +44,27 @@ type WorkerWithFunc struct {
43
44
// run starts a goroutine to repeat the process
44
45
// that performs the function calls.
45
46
func (w * WorkerWithFunc ) run () {
47
+ w .pool .incRunning ()
46
48
go func () {
47
49
defer func () {
48
50
if p := recover (); p != nil {
49
51
w .pool .decRunning ()
50
52
if w .pool .PanicHandler != nil {
51
53
w .pool .PanicHandler (p )
52
54
} else {
53
- panic ( p )
55
+ log . Printf ( "worker exits from a panic: %v" , p )
54
56
}
55
57
}
56
58
}()
57
59
58
60
for args := range w .args {
59
61
if args == nil {
60
62
w .pool .decRunning ()
61
- w .pool .cachePool .Put (w )
63
+ w .pool .workerCache .Put (w )
62
64
return
63
65
}
64
66
w .pool .poolFunc (args )
65
- w .pool .putWorker (w )
67
+ w .pool .revertWorker (w )
66
68
}
67
69
}()
68
70
}
You can’t perform that action at this time.
0 commit comments