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

Function performQueries

chapter7/patterns/pool/main/main.go:77–91  ·  view source on GitHub ↗

performQueries tests the resource pool of connections.

(query int, p *pool.Pool)

Source from the content-addressed store, hash-verified

75
76// performQueries tests the resource pool of connections.
77func performQueries(query int, p *pool.Pool) {
78 // Acquire a connection from the pool.
79 conn, err := p.Acquire()
80 if err != nil {
81 log.Println(err)
82 return
83 }
84
85 // Release the connection back to the pool.
86 defer p.Release(conn)
87
88 // Wait to simulate a query response.
89 time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
90 log.Printf("Query: QID[%d] CID[%d]\n", query, conn.(*dbConnection).ID)
91}

Callers 1

mainFunction · 0.85

Calls 2

AcquireMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected