MCPcopy Create free account
hub / github.com/goinaction/code / New

Function New

chapter7/patterns/pool/pool.go:29–38  ·  view source on GitHub ↗

New creates a pool that manages resources. A pool requires a function that can allocate a new resource and the size of the pool.

(fn func() (io.Closer, error), size uint)

Source from the content-addressed store, hash-verified

27// function that can allocate a new resource and the size of
28// the pool.
29func New(fn func() (io.Closer, error), size uint) (*Pool, error) {
30 if size <= 0 {
31 return nil, errors.New("Size value too small.")
32 }
33
34 return &Pool{
35 factory: fn,
36 resources: make(chan io.Closer, size),
37 }, nil
38}
39
40// Acquire retrieves a resource from the pool.
41func (p *Pool) Acquire() (io.Closer, error) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected