Q1: You never do value, ok <- ch
on an un-closed channel: in NB you execute this statement after closing ch
, and in main you execute it after reading all from ch in the for loop. Why do you expect to ever return ok==true
to indicate the channel is un-closed?
Q2: Once 3 is consumed from ch in main NB may run again and print before main starts printing. You have absolutely no synchronization between NB and main. Again: What do you expect from such code?
If you want to emulate a generator for fibonacci numbers you should not read in NB from ch. This has nothing to do with buffering. Buffered channels just allow some goroutines to execute longer before blocking on the channel send.