@@ -27,19 +27,19 @@ type dbConnection struct {
2727 ID int32
2828}
2929
30- // Close implements the interface for the pool package.
31- // Close performs any resource release management.
30+ // Close implements the io.Closer interface so dbConnection
31+ // can be managed by the pool. Close performs any resource
32+ // release management.
3233func (dbConn * dbConnection ) Close () error {
3334 fmt .Println ("Close: Connection" , dbConn .ID )
3435 return nil
3536}
3637
37- // isCounter provides support for giving each
38- // connection a unique id.
38+ // idCounter provides support for giving each connection a unique id.
3939var idCounter int32
4040
41- // createConnection is a factory method called by the pool
42- // framework when new connections are needed.
41+ // createConnection is a factory method that will be called by
42+ // the pool when a new connection is needed.
4343func createConnection () (io.Closer , error ) {
4444 id := atomic .AddInt32 (& idCounter , 1 )
4545 fmt .Println ("Create: New Connection" , id )
@@ -49,17 +49,16 @@ func createConnection() (io.Closer, error) {
4949
5050// main is the entry point for all Go programs.
5151func main () {
52- var wg sync.WaitGroup // waits for program to finish
52+ var wg sync.WaitGroup
5353 wg .Add (maxGoroutines )
5454
55- // Create the buffered channel to hold
56- // and manage the connections.
55+ // Create the pool to manage our connections.
5756 p , err := pool .New (createConnection , pooledResources )
5857 if err != nil {
5958 fmt .Println (err )
6059 }
6160
62- // Perform queries using a connection from the pool.
61+ // Perform queries using connections from the pool.
6362 for query := 0 ; query < maxGoroutines ; query ++ {
6463 // Each goroutine needs its own copy of the query
6564 // value else they will all be sharing the same query
0 commit comments