Skip to content

Instantly share code, notes, and snippets.

@umit
Created April 9, 2021 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umit/5806beb9c9b8df64437eaad3bb55bcee to your computer and use it in GitHub Desktop.
Save umit/5806beb9c9b8df64437eaad3bb55bcee to your computer and use it in GitHub Desktop.
Countdownlatch example
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