Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"fmt"
)
/**
Channel では、channel の所有者と利用者(消費者)の役割分担をキチンとしておく。
*/
func main() {
chanOwner := func() <-chan int {
resultCh := make(chan int, 5)
go func() {
defer close(resultCh)
for i := 0; i < 5 ; i++ {
resultCh <- i
}
}()
return resultCh
}
for ch := range chanOwner() {
fmt.Printf("ch : %d\n", ch)
}
fmt.Println("Done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment