Is it possible for data coming in through a channel in golang to get ignored if it is not caught at the right moment inside a select statement?
For example, lets say there is this select statement:
for {
select {
case <-timer.C:
//block A
default:
// block B takes 2 seconds.
}
}
If timer ends while block B is running, does block A still run in the next iteration of the loop or does the channel's incoming data get lost?
When the timer expires, it will send the current time on C. If no one is reading from C at the time, the send will block, so it will wait until the value is received. In this case, it will wait till the next iteration of the loop.
Channels are designed to be a synchronization mechanism, so they don't require readers and writers to be already synchronized.