Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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


Image Added


References

...