title: golang timer blocking in goroutines
body: <p>Below code is from  <a href="https://gobyexample.com/timers" rel="nofollow">go by example - timers</a></p>
  
  <pre><code>package main
  
  import (
      "time"
      "fmt"
  )
  
  func main() {
      runtime.GOMAXPROCS(runtime.NumCPU())
      timer1 := time.NewTimer(time.Second * 1)
  
      &lt;-timer1.C
      fmt.Println("Timer 1 expired")
  
      timer2 := time.NewTimer(300) //change the duration to be more shorter
      go func() {
          &lt;-timer2.C
          fmt.Printf("Timer 2 expired")
      }()
  
      stop2 := timer2.Stop()
      if stop2 {
          fmt.Printf("Timer 2 stopped")
      }
  }
  </code></pre>
  
  <p>If I run above code, the output will be like(result one):</p>
  
  <pre><code>Timer 1 expired
  Timer 2 stopped
  </code></pre>
  
  <p>but if I change the body of the anonymous func to be:</p>
  
  <pre><code>fmt.Printf("Timer 2 expired")
  &lt;-timer2.C
  </code></pre>
  
  <p>the output is still like before. I'm confused, why the second output is not like(result two):</p>
  
  <pre><code>Timer 1 expired
  Timer 2 expired
  Timer 2 stopped
  </code></pre>
  
  <p>As per my understanding <em>&lt;-timer2.C</em> blocks the remain of goroutine until the timer channel get a value, so if I put <em>fmt.Printf("Timer 2 expired")</em> after <em>&lt;-timer2.C</em> the output will like result one, but if I put <em>fmt.Printf("Timer 2 expired")</em> before <em>&lt;-timer2.C</em>, I think the print action will not be blocked.</p>
  
  <p>Hope someone could give me a hand, thank you all.</p>