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

Function main

chapter7/patterns/pool/main/main.go:47–74  ·  view source on GitHub ↗

main is the entry point for all Go programs.

()

Source from the content-addressed store, hash-verified

45
46// main is the entry point for all Go programs.
47func main() {
48 var wg sync.WaitGroup
49 wg.Add(maxGoroutines)
50
51 // Create the pool to manage our connections.
52 p, err := pool.New(createConnection, pooledResources)
53 if err != nil {
54 log.Println(err)
55 }
56
57 // Perform queries using connections from the pool.
58 for query := 0; query < maxGoroutines; query++ {
59 // Each goroutine needs its own copy of the query
60 // value else they will all be sharing the same query
61 // variable.
62 go func(q int) {
63 performQueries(q, p)
64 wg.Done()
65 }(query)
66 }
67
68 // Wait for the goroutines to finish.
69 wg.Wait()
70
71 // Close the pool.
72 log.Println("Shutdown Program.")
73 p.Close()
74}
75
76// performQueries tests the resource pool of connections.
77func performQueries(query int, p *pool.Pool) {

Callers

nothing calls this directly

Calls 3

performQueriesFunction · 0.85
AddMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected