Created
April 9, 2021 10:42
-
-
Save umit/5806beb9c9b8df64437eaad3bb55bcee to your computer and use it in GitHub Desktop.
Countdownlatch example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
const numGreeters = 10 | |
hello := func(wg *CountDownLatch, id int) { | |
defer wg.Done() | |
time.Sleep(10 * time.Second) | |
fmt.Printf("Hello from %v!\n", id) | |
} | |
waitGroup := CountDownLatch{} | |
waitGroup.Add(numGreeters) | |
for i := 0; i < numGreeters; i++ { | |
go hello(&waitGroup, i) | |
} | |
await := waitGroup.Await(5 * time.Second) | |
fmt.Printf("Await status: %t \n", await) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment