I have a default cause in a select statement that I want to do nothing, just continue, but leaving the line blank stops anything in the statement from happening
select {
case quit_status := <-quit:
if quit_status == true {
fmt.Printf("********************* GOROUTINE [%d] Received QUIT MSG\n", id)
return
}
default:
fmt.Printf("GOROUTINE [%d] step: %d, NO QUIT MSG\n", id, i)
}
With Python >= 3.0, you should use ... (Ellipsis) instead of pass to indicate "finish later" blocks.
Basic of Golang PointerPass by value will pass the value of the variable into the method, or we can say that the original variable 'copy' the value into another memory location and pass the newly created one into the method.
The pass statement is used as a placeholder for future code. When the pass statement is executed, nothing happens, but you avoid getting an error when empty code is not allowed. Empty code is not allowed in loops, function definitions, class definitions, or in if statements.
You don't have pass or equivalent keyword. But you can write equivalent code without any such keyword. def f(): pass. becomes void f() {} and class C: pass.
The default
case in a select
statement is intended to provide non-blocking I/O for channel reads and writes. The code in the default
case is executed whenever none of the channels in any of the cases are ready to be read/written to.
So in your case, the default
block is executed if the quit channel has nothing to say.
You can simply remove the default case and it will block on the quit_status := <-quit
case until a value is available in quit
.. which is probably what you are after in this instance.
If you want to immediately continue executing code after the select statement, you should run this select statement in a separate goroutine:
go func() {
select {
case quit_status := <-quit:
...
}
}()
// Execution continues here immediately.
As @StephenWeinberg pointed out, there is no pass statement in go. Simply put nothing in the case when the channel hits something.
select {
case <-ch:
// do something
case <-time.After(2*time.Second):
// timeout
default:
// do nothing aka pass
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With