A pool to facilitate the creation and reuse of objects
Using NewPool to create a pool with capacity of 10.
package main
import (
"github.com/shomali11/xpool"
"time"
)
type Object struct{}
func main() {
factory := func() interface{} {
return &Object{}
}
pool := xpool.NewPool(10, factory)
for i := 0; i < 10; i++ {
go func() {
object := pool.Get().(*Object)
pool.Return(object)
}()
}
time.Sleep(time.Second)
}