Created
January 13, 2020 20:45
-
-
Save prabaprakash/d3f192587cd86477d558921f8295b056 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
| "sync" | |
| ) | |
| var wg sync.WaitGroup | |
| func say(s string) { | |
| for i := 0; i < 5; i++ { | |
| time.Sleep(100 * time.Millisecond) | |
| fmt.Println(s) | |
| } | |
| wg.Done() // <=> wg.Add(-1) | |
| } | |
| func main() { | |
| wg.Add(2) // register two tasks. | |
| go say("world") | |
| say("hello") | |
| fmt.Println("re") | |
| wg.Wait() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment