Skip to content

Instantly share code, notes, and snippets.

@Israel-Miles
Created September 27, 2021 15:32
Show Gist options
  • Save Israel-Miles/84afdf8c03187bff02cb2715b2e1129e to your computer and use it in GitHub Desktop.
Save Israel-Miles/84afdf8c03187bff02cb2715b2e1129e to your computer and use it in GitHub Desktop.
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