Skip to content

Commit 6ec6e9f

Browse files
committed
Initial commit
0 parents  commit 6ec6e9f

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

LICENSE.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
BSD 3-Clause License
2+
3+
Copyright © 2025 - Marius Romeiser. All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without modification, are permitted
6+
provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this list of conditions
9+
and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
12+
and the following disclaimer in the documentation and/or other materials provided with the distribution.
13+
14+
3. Neither the name of copyright holder nor the names of its contributors may be used to endorse
15+
or promote products derived from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
18+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
20+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
23+
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# generic_syncpool
2+
3+
The "generic_syncpool" package offers a generic wrapper for sync.Pool. For more details, you can refer to the sync.Pool documentation at: https://pkg.go.dev/sync.
4+
5+
## Installation
6+
7+
```bash
8+
go install https://github.com/mariusromeiser/generic_syncpool@latest
9+
```
10+
11+
## Documentation
12+
13+
[Documentation](https://pkg.go.dev/sync)
14+
15+
https://pkg.go.dev/sync
16+
17+
## License
18+
19+
BSD 3-Clause License
20+
21+
## Author
22+
23+
Copyright © 2025 - Marius Romeiser. All rights reserved.

generic_syncpool.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// BSD 3-Clause License
2+
//
3+
// Copyright © 2009 - The Go Authors. All rights reserved.
4+
//
5+
// Copyright © 2025 - Marius Romeiser. All rights reserved.
6+
// _ __
7+
// ____ ____ ____ ___ _____(_)____ _______ ______ _________ ____ ____ / /
8+
// / __ `/ _ \/ __ \/ _ \/ ___/ / ___/ / ___/ / / / __ \/ ___/ __ \/ __ \/ __ \/ /
9+
// / /_/ / __/ / / / __/ / / / /__ (__ ) /_/ / / / / /__/ /_/ / /_/ / /_/ / /
10+
// \__, /\___/_/ /_/\___/_/ /_/\___/____/____/\__, /_/ /_/\___/ .___/\____/\____/_/
11+
// /____/ /_____/ /____/ /_/
12+
//
13+
// The "generic_syncpool" package offers a generic wrapper for sync.Pool.
14+
// For more details, you can refer to the sync.Pool documentation at: https://pkg.go.dev/sync.
15+
16+
package generic_syncpool
17+
18+
import (
19+
"sync"
20+
)
21+
22+
// Pool represents a new generic sync.Pool
23+
type Pool[T any] struct {
24+
syncpool sync.Pool
25+
}
26+
27+
// New create and returns a new instance of Pool
28+
func New[T any]() *Pool[T] {
29+
return &Pool[T]{
30+
syncpool: sync.Pool{
31+
New: func() any { return new(T) },
32+
},
33+
}
34+
}
35+
36+
// A generic wrapper around sync.Pool's Get method.
37+
// https://pkg.go.dev/sync#Pool.Get
38+
func (p *Pool[T]) Get() *T {
39+
return p.syncpool.Get().(*T)
40+
}
41+
42+
// A generic wrapper around sync.Pool's Put method.
43+
// https://pkg.go.dev/sync#Put.Pool
44+
func (p *Pool[T]) Put(x *T) {
45+
p.syncpool.Put(x)
46+
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/mariusromeiser/generic_syncpool
2+
3+
go 1.23.4

0 commit comments

Comments
 (0)