File tree 1 file changed +19
-1
lines changed
1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ import (
18
18
"time"
19
19
20
20
"github.com/panjf2000/ants/v2"
21
+
22
+ "github.com/panjf2000/gnet/v2/pkg/logging"
21
23
)
22
24
23
25
const (
@@ -40,9 +42,25 @@ func init() {
40
42
// Pool is the alias of ants.Pool.
41
43
type Pool = ants.Pool
42
44
45
+ type antsLogger struct {
46
+ logging.Logger
47
+ }
48
+
49
+ // Printf implements the ants.Logger interface.
50
+ func (l antsLogger ) Printf (format string , args ... interface {}) {
51
+ l .Infof (format , args ... )
52
+ }
53
+
43
54
// Default instantiates a non-blocking *WorkerPool with the capacity of DefaultAntsPoolSize.
44
55
func Default () * Pool {
45
- options := ants.Options {ExpiryDuration : ExpiryDuration , Nonblocking : Nonblocking }
56
+ options := ants.Options {
57
+ ExpiryDuration : ExpiryDuration ,
58
+ Nonblocking : Nonblocking ,
59
+ Logger : & antsLogger {logging .GetDefaultLogger ()},
60
+ PanicHandler : func (i interface {}) {
61
+ logging .Errorf ("goroutine pool panic: %v" , i )
62
+ },
63
+ }
46
64
defaultAntsPool , _ := ants .NewPool (DefaultAntsPoolSize , ants .WithOptions (options ))
47
65
return defaultAntsPool
48
66
}
You can’t perform that action at this time.
0 commit comments