Skip to content

Instantly share code, notes, and snippets.

@alexrios
Created June 9, 2021 10:30
Show Gist options
  • Save alexrios/4e052c046e988dbb06d4122b42e2bd82 to your computer and use it in GitHub Desktop.
Save alexrios/4e052c046e988dbb06d4122b42e2bd82 to your computer and use it in GitHub Desktop.
Sync Package - Wait Group
package main
import (
"fmt"
"sync"
"time"
)
func main() {
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
time.Sleep(500 * time.Millisecond)
greeter("routine A")
wg.Done()
}()
go func() {
time.Sleep(200 * time.Millisecond)
greeter("routine B")
wg.Done()
}()
wg.Wait()
fmt.Println("All members in the group are done")
}
func greeter(s string) {
fmt.Println(s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment