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

Function main

chapter7/patterns/work/main/main.go:34–64  ·  view source on GitHub ↗

main is the entry point for all Go programs.

()

Source from the content-addressed store, hash-verified

32
33// main is the entry point for all Go programs.
34func main() {
35 // Create a work pool with 2 goroutines.
36 p := work.New(2)
37
38 var wg sync.WaitGroup
39 wg.Add(100 * len(names))
40
41 for i := 0; i < 100; i++ {
42 // Iterate over the slice of names.
43 for _, name := range names {
44 // Create a namePrinter and provide the
45 // specific name.
46 np := namePrinter{
47 name: name,
48 }
49
50 go func() {
51 // Submit the task to be worked on. When RunTask
52 // returns we know it is being handled.
53 p.Run(&np)
54 wg.Done()
55 }()
56 }
57 }
58
59 wg.Wait()
60
61 // Shutdown the work pool and wait for all existing work
62 // to be completed.
63 p.Shutdown()
64}

Callers

nothing calls this directly

Calls 3

AddMethod · 0.80
RunMethod · 0.80
ShutdownMethod · 0.80

Tested by

no test coverage detected