Skip to content

Commit 30b3462

Browse files
committed
优化代码
1 parent 12fd819 commit 30b3462

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

option.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,17 @@ func WithFastFailed() Option {
7171
// WithPoolFullErr sets newPoolFullErr to config.
7272
func WithPoolFullErr(newPoolFullErr func(ctx context.Context) error) Option {
7373
return func(conf *config) {
74-
conf.newPoolFullErrFunc = newPoolFullErr
74+
if newPoolFullErr != nil {
75+
conf.newPoolFullErrFunc = newPoolFullErr
76+
}
7577
}
7678
}
7779

7880
// WithPoolClosedErr sets newPoolClosedErr to config.
7981
func WithPoolClosedErr(newPoolClosedErr func(ctx context.Context) error) Option {
8082
return func(conf *config) {
81-
conf.newPoolClosedErrFunc = newPoolClosedErr
83+
if newPoolClosedErr != nil {
84+
conf.newPoolClosedErrFunc = newPoolClosedErr
85+
}
8286
}
8387
}

option_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ func TestWithPoolFullErr(t *testing.T) {
3232
if fmt.Sprintf("%p", conf.newPoolFullErrFunc) != fmt.Sprintf("%p", newPoolFullErr) {
3333
t.Fatalf("conf.newPoolFullErr %p is wrong", conf.newPoolFullErrFunc)
3434
}
35+
36+
WithPoolFullErr(nil)(conf)
37+
38+
if fmt.Sprintf("%p", conf.newPoolFullErrFunc) != fmt.Sprintf("%p", newPoolFullErr) {
39+
t.Fatalf("conf.newPoolFullErr %p is wrong", conf.newPoolFullErrFunc)
40+
}
3541
}
3642

3743
// go test -v -cover -run=^TestWithPoolClosedErr$
@@ -46,4 +52,10 @@ func TestWithPoolClosedErr(t *testing.T) {
4652
if fmt.Sprintf("%p", conf.newPoolClosedErrFunc) != fmt.Sprintf("%p", newPoolClosedErr) {
4753
t.Fatalf("conf.newPoolClosedErr %p is wrong", conf.newPoolClosedErrFunc)
4854
}
55+
56+
WithPoolClosedErr(nil)(conf)
57+
58+
if fmt.Sprintf("%p", conf.newPoolClosedErrFunc) != fmt.Sprintf("%p", newPoolClosedErr) {
59+
t.Fatalf("conf.newPoolClosedErr %p is wrong", conf.newPoolClosedErrFunc)
60+
}
4961
}

0 commit comments

Comments
 (0)