File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,37 +3,25 @@ package xsync
33import "sync"
44
55type SyncPool [T any ] struct {
6- New func () T
76 pool sync.Pool
8- once sync.Once
97}
108
119// NewSyncPool creates a new SyncPool with specified init function
1210func NewSyncPool [T any ](new func () T ) * SyncPool [T ] {
1311 sp := & SyncPool [T ]{
14- New : new ,
12+ pool : sync.Pool {New : func () interface {} {
13+ return new ()
14+ }},
1515 }
16- sp .init ()
1716 return sp
1817}
1918
20- // init initializes the SyncPool
21- func (s * SyncPool [T ]) init () {
22- s .once .Do (func () {
23- s .pool .New = func () interface {} {
24- return s .New ()
25- }
26- })
27- }
28-
2919// Get wraps sync.Pool.Get.
3020func (s * SyncPool [T ]) Get () T {
31- s .init ()
3221 return s .pool .Get ().(T )
3322}
3423
3524// Put wraps sync.Pool.Put.
3625func (s * SyncPool [T ]) Put (x T ) {
37- s .init ()
3826 s .pool .Put (x )
3927}
You can’t perform that action at this time.
0 commit comments