aboutsummaryrefslogtreecommitdiff
path: root/gpool
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-21 21:12:36 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-21 21:14:13 +0800
commit561db30e03d5cf22709c8dbf091c5ea61717695e (patch)
treed36a66beae25001fbd9d6155d9369aa7461c333b /gpool
parentmisc: Remove underscores (diff)
downloadgo-lindenii-common-561db30e03d5cf22709c8dbf091c5ea61717695e.tar.gz
go-lindenii-common-561db30e03d5cf22709c8dbf091c5ea61717695e.tar.zst
go-lindenii-common-561db30e03d5cf22709c8dbf091c5ea61717695e.zip
gpool: Generic wrapper for sync.Pool
Diffstat (limited to 'gpool')
l---------gpool/LICENSE1
-rw-r--r--gpool/pool.go16
2 files changed, 17 insertions, 0 deletions
diff --git a/gpool/LICENSE b/gpool/LICENSE
new file mode 120000
index 0000000..97a673a
--- /dev/null
+++ b/gpool/LICENSE
@@ -0,0 +1 @@
+../LICENSE.3BSD \ No newline at end of file
diff --git a/gpool/pool.go b/gpool/pool.go
new file mode 100644
index 0000000..9959b0d
--- /dev/null
+++ b/gpool/pool.go
@@ -0,0 +1,16 @@
+package gpool
+
+import "sync"
+
+type Pool[T any] struct {
+ p sync.Pool
+ New func() T
+}
+
+func (p *Pool[T]) Get() T {
+ return p.p.Get().(T)
+}
+
+func (p *Pool[T]) Put(x T) {
+ p.p.Put(x)
+}