doWork simulates a goroutine performing work and checking the Shutdown flag to terminate early.
(name string)
| 41 | // doWork simulates a goroutine performing work and |
| 42 | // checking the Shutdown flag to terminate early. |
| 43 | func 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 | } |