Original post

Hi,

I have two goroutines:

  1. sends even numbers in the channel
  2. sends odd numbers in the same channel.

In the main function, I want to print those numbers. The main function should print values in the sequence:
1
2
3
4

I have used two channels to synchronize both goroutines ie even and odd. so the first goroutine will send 0, then the second will send 1, first will send 2, and so on.

Can you please help me to optimize this code: https://play.golang.org/p/dgVWW8ew2A6
I want to use only one channel for synchronization.

Thanks