go select syntax

tags: learning go programming

content

  • in this example:

    Transclude of go-channel-select#go-select

  • look at for range 2

    • without for loop, select will only be run once, and only 1 msg from 1 channel will be printed out.
  • if it’s more than range 2, say, if it’s range 3, it will cause go-deadlock!

  • why is this a deadlock?

    • if select is 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!)
  • for range 2 simply means wait for two results:

    Transclude of go-channel-select#select-is-wait

up

go-channel-select

down