Re: [go-nuts] Hesitating on using cached / un-cached channels

2022-04-12 Thread Zhaoxun Yan
Yes you are right! Unbuffered channel is solid! package main import ( "fmt" "time" ) var c = make(chan int) func report(){ for{ select{ case n:= <- c: fmt.Println(n, time.Now().Format("2006-01-02 15:04:05")) default:

Re: [go-nuts] Hesitating on using cached / un-cached channels

2022-04-11 Thread burak serdar
An unbuffered channel is a synchronization mechanism. A send on an unbuffered channel will block until there is a concurrent receive from another goroutine. Your program has only one goroutine. A send to an unbuffered channel will always deadlock, so will a receive from it. So the problem you are

Re: [go-nuts] Hesitating on using cached / un-cached channels

2022-04-11 Thread robert engels
There are numerous ways to create a “dead lock” in any program (this may actually be a “live lock” but I didn’t fully understand your statement - this is just one of them. > On Apr 11, 2022, at 9:29 PM, Zhaoxun Yan wrote: > > Hi guys, I have a great demonstration on why an un-cached channel

[go-nuts] Hesitating on using cached / un-cached channels

2022-04-11 Thread Zhaoxun Yan
Hi guys, I have a great demonstration on why an un-cached channel might malfunction while receiving: package main import( "fmt" "time" ) func main(){ t := time.NewTicker(time.Second * 3) stopnow := make(chan bool) //stopnow := make(chan bool, 1) //cached channel