| 18 | var wg sync.WaitGroup |
| 19 | |
| 20 | func main() { |
| 21 | // Create an unbuffered channel. |
| 22 | track := make(chan int) |
| 23 | |
| 24 | // Add a count of one for the last runner. |
| 25 | // We only add one because all we care about is the last runner in the race telling us that he |
| 26 | // is done. |
| 27 | wg.Add(1) |
| 28 | |
| 29 | // Create a first runner to his mark. |
| 30 | go Runner(track) |
| 31 | |
| 32 | // The main Goroutine start the race (shoot the gun). |
| 33 | // At this moment, we know that on the other side, a Goroutine is performing a receive. |
| 34 | track <- 1 |
| 35 | |
| 36 | // Wait for the race to finish. |
| 37 | wg.Wait() |
| 38 | } |
| 39 | |
| 40 | // Runner simulates a person running in the relay race. |
| 41 | // This Runner doesn't have a loop because it's gonna do everything from the beginning to end and |