When I compile the following code, it generates
*syntax error: unexpected case, expecting expression*
at line *case workerAddr = <- mr.registerChannel:*
I do not know why it happens since I just want to workerAddr to be set by either channel. Any suggestion will be appreciated.
for i:= 0; i < mr.nMap; i++ {
go func(jobCount) {
for {
var workerAddr string
Select {
// get a worker either from registerChannel or from idle channel
case workerAddr = <- mr.registerChannel:
case workerAddr = <- mr.idleChannel:
}
// omit the following code
}
}(i)
}
It happens because you have written Select
when you should have written select
.
None of the Go keywords are capitalized, so when the compiler sees a capitalized word, it knows immediately that it's not an expression, and therefore a syntax error.