Skip to content

Commit 43a0708

Browse files
authored
Merge pull request #3 from FishGoddess/develop
v0.2.1
2 parents f79e4df + 30b3462 commit 43a0708

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## 📜 历史版本的特性介绍 (Features in old versions)
22

3+
### v0.2.1
4+
5+
> 此版本发布于 2025-04-12
6+
7+
* 优化代码
8+
39
### v0.2.0
410

511
> 此版本发布于 2025-04-12

_icons/coverage.svg

Lines changed: 2 additions & 2 deletions
Loading

option.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ var (
1717
type config struct {
1818
fastFailed bool
1919

20-
newPoolFullErr func(ctx context.Context) error
21-
newPoolClosedErr func(ctx context.Context) error
20+
newPoolFullErrFunc func(ctx context.Context) error
21+
newPoolClosedErrFunc func(ctx context.Context) error
2222
}
2323

2424
func newDefaultConfig() *config {
@@ -31,14 +31,30 @@ func newDefaultConfig() *config {
3131
}
3232

3333
conf := &config{
34-
fastFailed: false,
35-
newPoolFullErr: newPoolFullErr,
36-
newPoolClosedErr: newPoolClosedErr,
34+
fastFailed: false,
35+
newPoolFullErrFunc: newPoolFullErr,
36+
newPoolClosedErrFunc: newPoolClosedErr,
3737
}
3838

3939
return conf
4040
}
4141

42+
func (c *config) newPoolFullErr(ctx context.Context) error {
43+
if c.newPoolFullErrFunc == nil {
44+
return nil
45+
}
46+
47+
return c.newPoolFullErrFunc(ctx)
48+
}
49+
50+
func (c *config) newPoolClosedErr(ctx context.Context) error {
51+
if c.newPoolClosedErrFunc == nil {
52+
return nil
53+
}
54+
55+
return c.newPoolClosedErrFunc(ctx)
56+
}
57+
4258
type Option func(conf *config)
4359

4460
func (o Option) ApplyTo(conf *config) {
@@ -56,7 +72,7 @@ func WithFastFailed() Option {
5672
func WithPoolFullErr(newPoolFullErr func(ctx context.Context) error) Option {
5773
return func(conf *config) {
5874
if newPoolFullErr != nil {
59-
conf.newPoolFullErr = newPoolFullErr
75+
conf.newPoolFullErrFunc = newPoolFullErr
6076
}
6177
}
6278
}
@@ -65,7 +81,7 @@ func WithPoolFullErr(newPoolFullErr func(ctx context.Context) error) Option {
6581
func WithPoolClosedErr(newPoolClosedErr func(ctx context.Context) error) Option {
6682
return func(conf *config) {
6783
if newPoolClosedErr != nil {
68-
conf.newPoolClosedErr = newPoolClosedErr
84+
conf.newPoolClosedErrFunc = newPoolClosedErr
6985
}
7086
}
7187
}

option_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ func TestWithPoolFullErr(t *testing.T) {
2626
return nil
2727
}
2828

29-
conf := &config{newPoolFullErr: nil}
29+
conf := &config{newPoolFullErrFunc: nil}
3030
WithPoolFullErr(newPoolFullErr)(conf)
3131

32-
if fmt.Sprintf("%p", conf.newPoolFullErr) != fmt.Sprintf("%p", newPoolFullErr) {
33-
t.Fatalf("conf.newPoolFullErr %p is wrong", conf.newPoolFullErr)
32+
if fmt.Sprintf("%p", conf.newPoolFullErrFunc) != fmt.Sprintf("%p", newPoolFullErr) {
33+
t.Fatalf("conf.newPoolFullErr %p is wrong", conf.newPoolFullErrFunc)
3434
}
3535

3636
WithPoolFullErr(nil)(conf)
3737

38-
if fmt.Sprintf("%p", conf.newPoolFullErr) != fmt.Sprintf("%p", newPoolFullErr) {
39-
t.Fatalf("conf.newPoolFullErr %p is wrong", conf.newPoolFullErr)
38+
if fmt.Sprintf("%p", conf.newPoolFullErrFunc) != fmt.Sprintf("%p", newPoolFullErr) {
39+
t.Fatalf("conf.newPoolFullErr %p is wrong", conf.newPoolFullErrFunc)
4040
}
4141
}
4242

@@ -46,16 +46,16 @@ func TestWithPoolClosedErr(t *testing.T) {
4646
return nil
4747
}
4848

49-
conf := &config{newPoolClosedErr: nil}
49+
conf := &config{newPoolClosedErrFunc: nil}
5050
WithPoolClosedErr(newPoolClosedErr)(conf)
5151

52-
if fmt.Sprintf("%p", conf.newPoolClosedErr) != fmt.Sprintf("%p", newPoolClosedErr) {
53-
t.Fatalf("conf.newPoolClosedErr %p is wrong", conf.newPoolClosedErr)
52+
if fmt.Sprintf("%p", conf.newPoolClosedErrFunc) != fmt.Sprintf("%p", newPoolClosedErr) {
53+
t.Fatalf("conf.newPoolClosedErr %p is wrong", conf.newPoolClosedErrFunc)
5454
}
5555

5656
WithPoolClosedErr(nil)(conf)
5757

58-
if fmt.Sprintf("%p", conf.newPoolClosedErr) != fmt.Sprintf("%p", newPoolClosedErr) {
59-
t.Fatalf("conf.newPoolClosedErr %p is wrong", conf.newPoolClosedErr)
58+
if fmt.Sprintf("%p", conf.newPoolClosedErrFunc) != fmt.Sprintf("%p", newPoolClosedErr) {
59+
t.Fatalf("conf.newPoolClosedErr %p is wrong", conf.newPoolClosedErrFunc)
6060
}
6161
}

0 commit comments

Comments
 (0)