Skip to content

Commit 725d8dc

Browse files
committed
fix
1 parent 081b6ae commit 725d8dc

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

internal/pool/pool.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func defaultCreateItem[T any, PT Item[T]](context.Context) (PT, error) {
129129
}
130130

131131
// makeCreateItemFunc wraps the createItem function with timeout handling
132-
func makeCreateItemFunc[PT Item[T], T any](
132+
func makeCreateItemFunc[PT Item[T], T any]( //nolint:funlen
133133
config Config[PT, T],
134134
done <-chan struct{},
135135
appendToIdle func(item PT) error,
@@ -206,6 +206,9 @@ func (p *Pool[PT, T]) onChangeStats() {
206206
}
207207

208208
func (p *Pool[PT, T]) Stats() Stats {
209+
p.mu.RLock()
210+
defer p.mu.RUnlock()
211+
209212
return Stats{
210213
Limit: p.config.limit,
211214
Idle: len(p.idle),
@@ -301,7 +304,10 @@ func (p *Pool[PT, T]) putItem(ctx context.Context, item PT) (finalErr error) {
301304
}
302305
}
303306

304-
func makeAsyncCloseItemFunc[PT Item[T], T any](closeTimeout time.Duration, done <-chan struct{}) func(ctx context.Context, item PT) {
307+
func makeAsyncCloseItemFunc[PT Item[T], T any](
308+
closeTimeout time.Duration,
309+
done <-chan struct{},
310+
) func(ctx context.Context, item PT) {
305311
return func(ctx context.Context, item PT) {
306312
closeItemCtx, closeItemCancel := xcontext.WithDone(xcontext.ValueOnly(ctx), done)
307313
defer closeItemCancel()

internal/xsync/mutex.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,25 @@ func (l *RWMutex) WithRLock(f func()) {
3333
f()
3434
}
3535

36-
func WithLock[T any](l interface {
37-
Lock()
38-
Unlock()
39-
}, f func() T) T {
36+
type (
37+
mutex interface {
38+
Lock()
39+
Unlock()
40+
}
41+
rwMutex interface {
42+
RLock()
43+
RUnlock()
44+
}
45+
)
46+
47+
func WithLock[T any](l mutex, f func() T) T {
4048
l.Lock()
4149
defer l.Unlock()
4250

4351
return f()
4452
}
4553

46-
func WithRLock[T any](l interface {
47-
RLock()
48-
RUnlock()
49-
}, f func() T) T {
54+
func WithRLock[T any](l rwMutex, f func() T) T {
5055
l.RLock()
5156
defer l.RUnlock()
5257

internal/xsync/mutex_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ func TestWithLock(t *testing.T) {
123123
func TestWithRLock(t *testing.T) {
124124
t.Run("sync.RWMutex", func(t *testing.T) {
125125
mtx := sync.RWMutex{}
126-
v := WithLock(&mtx, func() int {
126+
v := WithRLock(&mtx, func() int {
127127
return 123
128128
})
129129
require.Equal(t, 123, v)
130130
})
131131
t.Run("xsync.RWMutex", func(t *testing.T) {
132132
mtx := RWMutex{}
133-
v := WithLock(&mtx, func() int {
133+
v := WithRLock(&mtx, func() int {
134134
return 123
135135
})
136136
require.Equal(t, 123, v)

internal/xsync/set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (s *Set[T]) Values() []T {
4040
values := make([]T, 0, s.size.Load())
4141

4242
s.m.Range(func(k, v any) bool {
43-
values = append(values, k.(T))
43+
values = append(values, k.(T)) //nolint:forcetypeassert
4444

4545
return true
4646
})

0 commit comments

Comments
 (0)