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

Function doWork

chapter6/listing15/listing15.go:43–57  ·  view source on GitHub ↗

doWork simulates a goroutine performing work and checking the Shutdown flag to terminate early.

(name string)

Source from the content-addressed store, hash-verified

41// doWork simulates a goroutine performing work and
42// checking the Shutdown flag to terminate early.
43func doWork(name string) {
44 // Schedule the call to Done to tell main we are done.
45 defer wg.Done()
46
47 for {
48 fmt.Printf("Doing %s Work\n", name)
49 time.Sleep(250 * time.Millisecond)
50
51 // Do we need to shutdown.
52 if atomic.LoadInt64(&shutdown) == 1 {
53 fmt.Printf("Shutting %s Down\n", name)
54 break
55 }
56 }
57}

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected