For why close the error channel: Because if you don't close the error channel, the last return statement maybe blocked forever if there is no value in the chan. Receive from a closed chan will return immediately even if it's empty.
@able26632 жыл бұрын
nice sharing.
@mikei4min7 жыл бұрын
By the way Dave Cheney is a great author - dave.cheney.net/!
@FrenchPirate836 жыл бұрын
Minor, but could sem not have been a chan struct{} instead of a chan int?
@欧阳楚-h4e5 жыл бұрын
fatal error: all goroutines are asleep - deadlock!
@remariorichards82376 жыл бұрын
hi, why did you not close the error channel as well?
@niharrathod6 жыл бұрын
Same question. Any idea why?
@wangfenjin6 жыл бұрын
Because if you don't close the error channel, the last return statement maybe blocked forever if there is no value in the chan. Receive from a closed chan will return immediately even if it's empty.