diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-26 14:53:37 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-30 22:15:06 -0700 |
commit | 86063b41fc1a235930d6c79e6b7cd38ae8d8c147 (patch) | |
tree | 5c6b523a1c24062bbaba60bca1b7042b9976701c /lib/containers/syncpool.go | |
parent | f4f062d7d4ed730411e04ecd36ee36387e50739c (diff) |
Split lib/containers.Sync* to git.lukeshu.com/go/typedsync
Diffstat (limited to 'lib/containers/syncpool.go')
-rw-r--r-- | lib/containers/syncpool.go | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/lib/containers/syncpool.go b/lib/containers/syncpool.go deleted file mode 100644 index cb5398d..0000000 --- a/lib/containers/syncpool.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com> -// -// SPDX-License-Identifier: GPL-2.0-or-later - -package containers - -import ( - "sync" -) - -type SyncPool[T any] struct { - New func() T - - inner sync.Pool -} - -func (p *SyncPool[T]) Get() (val T, ok bool) { - _val := p.inner.Get() - switch { - case _val != nil: - //nolint:forcetypeassert // Typed wrapper around untyped lib. - return _val.(T), true - case p.New != nil: - return p.New(), true - default: - var zero T - return zero, false - } -} - -func (p *SyncPool[T]) Put(val T) { - p.inner.Put(val) -} |