If you execute it you are told on which lines the deadlock happens... fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan send]: main.main.func2() /Users/emuller/go/src/github.com/freeformz/tt/main.go:25 +0xce main.main() /Users/emuller/go/src/github.com/freeformz/tt/main.go:37 +0x118 exit status 2 main.go:25 is the line that says `done <- true`. The `done` channel isn't buffered and the first loop through will select that path, but there is not another goroutine selecting from done. so f() never returns. Deadlock. On Thu, Sep 1, 2016 at 10:04 AM Darren Hoo <darren....@gmail.com> wrote: > var wg sync.WaitGroup > > ints := make(chan int, 1) > done := make(chan bool) > > go func() { > for i := 0; i < 3; i++ { > ints <- i > } > close(ints) > }() > > f := func() { > wg.Add(1) > defer wg.Done() > > for { > i, ok := <-ints > if !ok { > done <- true > return > } > } > } > > exit: > for { > select { > case <-done: > break exit > default: > f() > } > } > wg.Wait() > > > > -- > 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. > -- 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.