Why does select in golang only works with channels in goroutine?
<p>Consider the following <a href="https://play.golang.org/p/M_ui4GNMMw" rel="nofollow">go playground</a></p>

<pre><code>    package main

    import "fmt"

    func main() {
        messages := make(chan string)

        messages &lt;- "my msg"

        select {
        case msg := &lt;-messages:
            fmt.Println("received message", msg)
        }

    }
</code></pre>

<p>The code above will reach error</p>

<pre><code>fatal error: all goroutines are asleep - deadlock!
</code></pre>

<p>However </p>

<p>if I change it to</p>

<pre><code>    package main

    import "fmt"

    func main() {
        messages := make(chan string)

        go func() {
            messages &lt;- "my msg"
        }()
        select {
        case msg := &lt;-messages:
            fmt.Println("received message", msg)
        }

    }
</code></pre>

<p>It will work.</p>

<p>Is there a particular reason for this behavior?</p>

<p>Shouldn't the code execute in a sequential manner in the first case so that by the time the select statement is reached, the msg will be passed and it will catch the case <code>msg := &lt;-messages</code> ?</p>