...
Code Block |
---|
package main import ( "fmt" "time" ) func main(){ //make channel of type string c := make(chan,string) //run in background go count("sheep", c) //loop until count function closes the channel for { msg, open := <- c if !open { //channel closed, break out of for loop break } } fmt.Println(msg) } func count(thing string, c chan string) { for i:=0; i <= 5; i++ { //send message on channel c <- thing time.Sleep(time.Millisecond * 500) } //close channel close(c) } |
Organizing your Code
References
Reference | URL |
---|---|
Learn Go in 12 Minutes | https://www.youtube.com/watch?v=C8LgvuEBraI |
Concurrency in Go | https://www.youtube.com/watch?v=LvgVSSpwND8 |
Go Packages | https://golang.org/pkg/ |
Go By Examples | https://gobyexample.com/ |
...