Created
September 27, 2021 15:49
-
-
Save Israel-Miles/5152b77475865a5a449bafb0457b707d 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
func main() { | |
var wg sync.WaitGroup | |
channel := make(chan int) | |
wg.Add(2) | |
go sendToChannel(channel, &wg) | |
go receiveFromChannel(channel, &wg) | |
wg.Wait() | |
} | |
func sendToChannel(ch chan<- int, wg *sync.WaitGroup) { | |
defer wg.Done() | |
for i := 0; i < 10; i++ { | |
ch <- i | |
} | |
close(ch) | |
} | |
func receiveFromChannel(ch <-chan int, wg *sync.WaitGroup) { | |
defer wg.Done() | |
for msg := range ch { | |
fmt.Println(msg) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment