Skip to content

Instantly share code, notes, and snippets.

@luandevpro
Created August 2, 2020 06:44
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 luandevpro/d04ae3cfcda663bff9e6a637b4cf1ae1 to your computer and use it in GitHub Desktop.
Save luandevpro/d04ae3cfcda663bff9e6a637b4cf1ae1 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sync"
"time"
)
func WellCome1(s string) {
for i := 0; i < 5; i++ {
fmt.Println(s, ":", i)
}
wg.Done()
}
func WellCome2(s string) {
for i := 0; i < 5; i++ {
time.Sleep(100*time.Millisecond)
fmt.Println(s, ":", i)
}
wg.Done()
}
var wg sync.WaitGroup
func main() {
wg.Add(2)
go WellCome1("wellcome1")
go WellCome2("wellcome2")
wg.Wait()
time.Sleep(200 * time.Millisecond)
fmt.Println("hello main ")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment