@@ -13,30 +13,31 @@ import (
1313 "sync"
1414)
1515
16- // Pool manages a set of resources that can be shared safely by multiple goroutines.
17- // The resource being managed must implement to io.Closer interface.
16+ // Pool manages a set of resources that can be shared safely by
17+ // multiple goroutines. The resource being managed must implement
18+ // the io.Closer interface.
1819type Pool struct {
1920 sync.Mutex
2021 resources chan io.Closer
2122 factory func () (io.Closer , error )
2223 closed bool
2324}
2425
25- // ErrInvalidCapacity is returned when there has been an attempt to create an
26- // unbuffered pool.
27- var ErrInvalidCapacity = errors .New ("Capacity needs to be greater than zero ." )
26+ // ErrInvalidCapacity is returned when there has been an attempt
27+ // to create an unbuffered pool.
28+ var ErrInvalidCapacity = errors .New ("Capacity value too small ." )
2829
29- // New creates a pool that manages resources. A pool requires a function
30- // that can allocate a new resource and the number of resources that can
31- // be allocated.
32- func New (fn func () (io.Closer , error ), capacity uint ) (* Pool , error ) {
33- if capacity == 0 {
30+ // New creates a pool that manages resources. A pool requires a
31+ // function that can allocate a new resource and the number of
32+ // resources that can be allocated.
33+ func New (fn func () (io.Closer , error ), cap uint ) (* Pool , error ) {
34+ if cap == 0 {
3435 return nil , ErrInvalidCapacity
3536 }
3637
3738 return & Pool {
3839 factory : fn ,
39- resources : make (chan io.Closer , capacity ),
40+ resources : make (chan io.Closer , cap ),
4041 }, nil
4142}
4243
@@ -75,7 +76,7 @@ func (p *Pool) Release(r io.Closer) {
7576 case p .resources <- r :
7677 fmt .Println ("Release:" , "In Queue" )
7778
78- // If the queue is already at capacity we close the resource.
79+ // If the queue is already at cap we close the resource.
7980 default :
8081 fmt .Println ("Release:" , "Closing" )
8182 r .Close ()
0 commit comments