Skip to content

Instantly share code, notes, and snippets.

@luandevpro
Last active August 2, 2020 07:10
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/6642bb6e91c5b9384918148a83d5eb66 to your computer and use it in GitHub Desktop.
Save luandevpro/6642bb6e91c5b9384918148a83d5eb66 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sync"
"time"
)
func WellCome1(s string, in chan int) {
for i := 0; i < 5; i++ {
in <- i + 2
fmt.Println(s, ":", i)
}
}
func WellCome2(s string, out chan int) {
for i := 0; i < 5; i++ {
time.Sleep(50 * time.Millisecond)
result := <-out
fmt.Println(s, ":", result)
}
}
var wg sync.WaitGroup
func main() {
ch := make(chan int)
go WellCome1("wellcome1", ch)
go WellCome2("wellcome2", ch)
time.Sleep(300 * time.Millisecond)
fmt.Println("hello main ")
}
wellcome2 : 2
wellcome2 : 3
wellcome2 : 4
wellcome2 : 5
wellcome2 : 6
hello main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment