Skip to content

Instantly share code, notes, and snippets.

@bwangelme
Created April 21, 2020 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwangelme/5e71895d40130521b71828cef72adc1f to your computer and use it in GitHub Desktop.
Save bwangelme/5e71895d40130521b71828cef72adc1f to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sync"
)
var x = 0
func sendNumber(wg *sync.WaitGroup, ch chan<- int, nump *int) {
ch <- *nump + x
wg.Done()
}
func main() {
var wg sync.WaitGroup
var num = 123
var p = &num
wg.Add(1)
ch := make(chan int, 1)
go sendNumber(&wg, ch, p)
wg.Wait()
num = 789
fmt.Println(<-ch)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment