Skip to content

Instantly share code, notes, and snippets.

@prabaprakash
Created January 13, 2020 20:45
Show Gist options
  • Select an option

  • Save prabaprakash/d3f192587cd86477d558921f8295b056 to your computer and use it in GitHub Desktop.

Select an option

Save prabaprakash/d3f192587cd86477d558921f8295b056 to your computer and use it in GitHub Desktop.
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