Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created March 9, 2021 07:09
Show Gist options
  • Save velotiotech/97d7171d03956f40b7c04815acfc7589 to your computer and use it in GitHub Desktop.
Save velotiotech/97d7171d03956f40b7c04815acfc7589 to your computer and use it in GitHub Desktop.
func printData(c chan *int) {
time.Sleep(time.Second * 3)
data := <-c
fmt.Println("Data in channel is: ", *data)
}
func main() {
fmt.Println("Main started...")
var a = 10
b := &a
//create channel
c := make(chan *int)
go printData(c)
fmt.Println("Value of b before putting into channel", *b)
c <- b
a = 20
fmt.Println("Updated value of a:", a)
fmt.Println("Updated value of b:", *b)
time.Sleep(time.Second * 2)
fmt.Println("Main ended...")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment