FAQ
I am trying to understand go channels/select. This is a modification of the
go tour chapter about buffered channel creation.

I want this code to produce the output:
1
2
3
quit

But I am getting this instead
1
2
quit


package main

import (
  "fmt"
  "time"
)


func main() {
  c := make(chan int, 3)
  c <- 1
  c <- 2


  tick := time.Tick(2000 * time.Millisecond)


  go func(c chan int) {
    for v := range c {
      fmt.Println(v)
    }
    fmt.Println("quit")
  }(c)


  select {
  case <-tick:
    c <- 3
    close(c)
   }
}



Thanks for your help and remarks

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 5 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 7, '15 at 10:03a
activeMar 7, '15 at 7:13p
posts5
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase