go select syntax
tags: learning go programming
content
-
in this example:
Transclude of go-channel-select#go-select
-
look at
for range 2- without
forloop,selectwill only be run once, and only 1msgfrom 1 channel will be printed out.
- without
-
if it’s more than
range 2, say, if it’srange 3, it will cause go-deadlock! -
why is this a deadlock?
- if
selectis looped 3 times, when it’s the third time, there’s no more value being sent to the channel - hence the main thread will be always waiting (aka, being blocked!)
- if
-
for range 2simply meanswait for two results:Transclude of go-channel-select#select-is-wait