Re:Go Concurrency
by brunoqc on Thursday March 28, 2013 @11:03AM
(#5455191)
Anyone has any idea why the code from slide 5 doesn't print anything? http://play.golang.org/p/NtjHL3F1LC
[ Parent
| on HN ]
Because I shortened it for the slide. Add something at the end of main() that waits a bit (say time.Sleep(time.Minute)). What's happening is main() terminates before those goroutines get to run.
Oh thanks! Sorry for the noise.
You should open a channel, pass it to the go routine, and send a completion message from the goroutine, and then read from it before the end of main.
3 lines of code to show a cool festure and avoid an embarassing bug.