hi Bjoern >>> Why would you expect this? "result 1" is the fist value that was sent to the channel. Channels are sort of FIFO.
Yeah I know.. but what is the workaround to get latest c1 value which is retrieve just before timeout Do I need to use "for ( loop )" around Select till timeout to invoke res: = <c1 to flush it's value till get timeout? Please help Thanks, Abhi On Sunday, August 6, 2017 at 7:01:25 PM UTC+5:30, bjoern...@googlemail.com wrote: > > > > Am Sonntag, 6. August 2017 09:53:36 UTC+2 schrieb Abhijit Desai: >> >> Can you please help with below code to get output at specific cutoff time >> and exit >> >> Thanks in advance >> >> Abhi >> >> >> >> package main >> >> import "time" >> import "fmt" >> >> func main() { >> >> c1 := make(chan string) >> >> go func() { //Sending data after certain time >> >> c1 <- "result 1" >> >> time.Sleep(time.Second * 1) >> c1 <- "result 2 afer 1 sec" >> >> time.Sleep(time.Second * 1) >> c1 <- "result 2 afer 2 sec" >> >> time.Sleep(time.Second * 1) >> c1 <- "result 2 afer 3 sec" >> >> time.Sleep(time.Second * 1) >> c1 <- "result 2 afer 4 sec" >> >> time.Sleep(time.Second * 1) >> c1 <- "result 2 afer 5 sec" >> }() >> >> select { >> case <-time.After(time.Second * 4): { //cut off 4s and return the >> value >> res := <-c1 >> fmt.Println(res) // expecting result "result 2 afer 3 sec" >> but returning "result 1" >> > > Why would you expect this? "result 1" is the fist value that was sent to > the channel. Channels are sort of FIFO. > > >> } >> } >> } >> > -- 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 golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.