package main
import "fmt"
import "strconv"
func main() {
ch := make(chan string)
count := 2
for i := 0; i < count; i++ {
go get(ch)
}
add(ch)
for{}
}
func get(ch chan string) {
for {
i := <-ch
fmt.Println("get", i)
}
}
func add(ch chan string) {
for i := 0; i < 4; i++ {
t := strconv.FormatInt(int64(i), 10)
ch <- t
fmt.Println("add", t)
}
}
if count = 2 output:
1) get 0 add 0 add 1 add 2 get 1 get 3 get 2 add 3 as expected
if count = 3 output:
2) get 0 add 0 add 1 add 2 add 3
if channel is buffered ( ch := make(chan string, 10)) output:
3) add 0 add 1 add 2 add 3
But I expected everywhere result number 1
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.