Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to using a generic pool for channels in Connection
Signed-off-by: Ed Warnicke <hagbard@gmail.com>
- Loading branch information
1 parent
4516f0c
commit 4dfb8cd
Showing
3 changed files
with
62 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package genericpool | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
type Pool[T any] struct { | ||
p sync.Pool | ||
} | ||
|
||
func (p *Pool[T]) Get() T { | ||
return p.p.Get().(T) | ||
} | ||
|
||
func (p *Pool[T]) Put(x T) { | ||
p.p.Put(x) | ||
} | ||
|
||
func New[T any](f func() T) *Pool[T] { | ||
return &Pool[T]{ | ||
p: sync.Pool{ | ||
New: func() any { return f() }, | ||
}, | ||
} | ||
} |