I have the following code in a select
statement. finish
is of type bool
. Actually, I don't even care of the value as long as I just receive anything. However, Go gives me an unused variable error. How can I get around it?
case finish := <- termSig:
My current workaround is to Println(finish)
.
I had tried:-
case _ := <- termSig:
but that doesn't work either.
Just omit the variable and the :=
:
case <-termSig:
As is shown in the Go Tour when select
is introduced, you can have a case that doesn't initialize a new variable.
func fibonacci(c, quit chan int) {
x, y := 0, 1
for {
select {
case c <- x:
x, y = y, x+y
case <-quit: // looks like exactly your use case
fmt.Println("quit")
return
}
}
}