Skip to content

Instantly share code, notes, and snippets.

@drtaka
Created January 31, 2020 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drtaka/d0d61b5f550f8993005445c3bcfe8b1d to your computer and use it in GitHub Desktop.
Save drtaka/d0d61b5f550f8993005445c3bcfe8b1d to your computer and use it in GitHub Desktop.
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