Skip to content

Instantly share code, notes, and snippets.

@luandevpro

luandevpro/main.go

Last active Aug 2, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.