Created
June 9, 2021 10:30
-
-
Save alexrios/4e052c046e988dbb06d4122b42e2bd82 to your computer and use it in GitHub Desktop.
Sync Package - Wait Group
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" | |
"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