316632 (1) [Avatar] Offline
In the performQueries function within the pool example's main.go program we are requesting new resources, waiting a random period of time, and then releasing the resource to simulate work being done. This is fine but every goroutine requests a resource before any of the resources are released so we don't really see how the pool is working. Every release just closes the resource since the pool is full (and no more Acquire()'s will be called since all goroutines already have their own resources).

It took me awhile of looking at this code to really understand what was going on because of this but simply adding the following line:

time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)

before the p.Acquire() call lets some goroutines actually make use of the pool since requests are made after resources have been released back into the pool.