Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dumindu/fddc1b0d4b6eff3e554ff40b52a6bb60 to your computer and use it in GitHub Desktop.
Save dumindu/fddc1b0d4b6eff3e554ff40b52a6bb60 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
ch := make(chan int)
go write(ch)
for v := range ch {
fmt.Println(v)
}
}
func write(ch chan int) {
for i := 1; i <= 10; i++ {
ch <- i
}
close(ch) // 💡 Close the channel to inform to the receiver, there are no more values coming
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment