Created
September 27, 2021 15:32
-
-
Save Israel-Miles/84afdf8c03187bff02cb2715b2e1129e 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 string) | |
wg.Add(2) | |
go sendToChannel(channel, &wg) | |
go receiveFromChannel(channel, &wg) | |
wg.Wait() | |
} | |
func sendToChannel(ch chan<- string, wg *sync.WaitGroup) { | |
defer wg.Done() | |
ch <- "Sending a message to the channel" | |
} | |
func receiveFromChannel(ch <-chan string, wg *sync.WaitGroup) { | |
defer wg.Done() | |
fmt.Println(<-ch) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment