MCPcopy Index your code
hub / github.com/goinaction/code / Release

Method Release

chapter7/patterns/pool/pool.go:59–80  ·  view source on GitHub ↗

Release places a new resource onto the pool.

(r io.Closer)

Source from the content-addressed store, hash-verified

57
58// Release places a new resource onto the pool.
59func (p *Pool) Release(r io.Closer) {
60 // Secure this operation with the Close operation.
61 p.m.Lock()
62 defer p.m.Unlock()
63
64 // If the pool is closed, discard the resource.
65 if p.closed {
66 r.Close()
67 return
68 }
69
70 select {
71 // Attempt to place the new resource on the queue.
72 case p.resources <- r:
73 log.Println("Release:", "In Queue")
74
75 // If the queue is already at cap we close the resource.
76 default:
77 log.Println("Release:", "Closing")
78 r.Close()
79 }
80}
81
82// Close will shutdown the pool and close all existing resources.
83func (p *Pool) Close() {

Callers 1

performQueriesFunction · 0.45

Calls 3

LockMethod · 0.65
UnlockMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected