Go select
Go select is a control structure similar to switch but designed specifically for handling I/O operations and also for listening to data flow on channels. Each case must be a channel communication operation, either a send or a receive.
- If there is one case statement that can run, it is executed, and the rest are not executed
- If multiple case statements are ready to run, select randomly chooses one to execute, and the rest are not executed
- If there are no runnable case statements but there is a default statement, the default will be executed (note that the default statement in select is always runnable, which can be CPU-intensive, hence it's generally advised not to include it unless necessary)
- If there are no runnable case statements and no default statement, select will block until at least one case statement becomes runnable
select {
case communication1:
//...
case communication2:
//...
case communication3:
//...
default :
//...
}
Take a break
πππ γJade Dynasty EP49γGui Li and Xiao Bai went to the Qilidong and competed with the locals in drinking