Skip to content

Instantly share code, notes, and snippets.

@kkamara
Last active November 27, 2023 01:16
Show Gist options
  • Save kkamara/b773b33601503674f7feb7aa6c6c338f to your computer and use it in GitHub Desktop.
Save kkamara/b773b33601503674f7feb7aa6c6c338f to your computer and use it in GitHub Desktop.
closing channels go routines
package main
import (
"fmt"
)
func producer(chnl chan int) {
for i := 0; i < 10; i++ {
chnl <- i
}
close(chnl)
}
func main() {
ch := make(chan int)
go producer(ch)
for {
v, ok := <-ch
if ok == false {
break
}
fmt.Println("Received ", v, ok)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment