title: Anonymous function with goroutines
body: <p>I am trying to understand the difference between calling goroutine with/without anonymous function.
  When I try below code with anonymous function it works.</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "time"
  )
  
  func main() {
      ch := make(chan int)
  
      go func() {
        fmt.Println(&lt;-ch)
      }() 
      go send(1, ch)      
  
      time.Sleep(100 * time.Millisecond)
  }
  </code></pre>
  
  <p>Below code without a anonymous function fails with deadlock.</p>
  
  <pre><code>go fmt.Println(&lt;-ch) //fatal error: all goroutines are asleep - deadlock!
  </code></pre>
  
  <p>The code is available <a href="https://play.golang.org/p/QFKIlcrTTCV" rel="nofollow noreferrer">here</a></p>