Last active
August 2, 2020 07:10
-
-
Save luandevpro/6642bb6e91c5b9384918148a83d5eb66 to your computer and use it in GitHub Desktop.
This file contains 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" | |
"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 ") | |
} |
This file contains 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
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