https://github.com/rocketlaunchr/go-pool
A better Generic Pool (sync.Pool)
https://github.com/rocketlaunchr/go-pool
go golang pool sync
Last synced: 3 months ago
JSON representation
A better Generic Pool (sync.Pool)
- Host: GitHub
- URL: https://github.com/rocketlaunchr/go-pool
- Owner: rocketlaunchr
- License: mit
- Created: 2021-01-14T03:38:50.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-04-12T07:56:52.000Z (about 1 year ago)
- Last Synced: 2025-04-12T08:37:40.252Z (about 1 year ago)
- Topics: go, golang, pool, sync
- Language: Go
- Homepage:
- Size: 147 KB
- Stars: 54
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
⭐ the project to show your appreciation. :arrow_upper_right:
# A Generic sync.Pool 
This package is a **thin** wrapper over the `Pool` provided by the `sync` package. The `Pool` is an essential package to obtain maximum performance. It does so by reducing memory allocations.
## Extra Features
- Invalidate an item from the Pool (so it never gets used again)
- Set a maximum number of items for the Pool (Limit pool growth)
- Return the number of items in the pool (idle and in-use)
- Designed for concurrency
- **Fully Generic**
## When should I use a pool?
> If you frequently allocate many objects of the same type and you want to save some memory allocation and garbage allocation overhead — @jrv
Read [How did I improve latency by 700% using sync.Pool](https://www.akshaydeo.com/blog/2017/12/23/How-did-I-improve-latency-by-700-percent-using-syncPool)
## Example
```go
import "github.com/rocketlaunchr/go-pool"
type X struct {}
pool := pool.New(func() *X {
return &X{}
}, 5) // maximum of 5 items can be borrowed at a time
borrowed := pool.Borrow()
defer borrowed.Return()
// Use item here or mark as invalid
x := borrowed.Item() // Use Item of type: *X
borrowed.MarkAsInvalid()
```
Other useful packages
------------
- [awesome-svelte](https://github.com/rocketlaunchr/awesome-svelte) - Resources for killing react
- [dataframe-go](https://github.com/rocketlaunchr/dataframe-go) - Statistics and data manipulation
- [dbq](https://github.com/rocketlaunchr/dbq) - Zero boilerplate database operations for Go
- [electron-alert](https://github.com/rocketlaunchr/electron-alert) - SweetAlert2 for Electron Applications
- [google-search](https://github.com/rocketlaunchr/google-search) - Scrape google search results
- [igo](https://github.com/rocketlaunchr/igo) - A Go transpiler with cool new syntax such as fordefer (defer for for-loops)
- [mysql-go](https://github.com/rocketlaunchr/mysql-go) - Properly cancel slow MySQL queries
- [react](https://github.com/rocketlaunchr/react) - Build front end applications using Go
- [remember-go](https://github.com/rocketlaunchr/remember-go) - Cache slow database queries
- [testing-go](https://github.com/rocketlaunchr/testing-go) - Testing framework for unit testing
### Logo Credits
1. Renee French (gopher)
2. Samuel Jirénius (illustration)