title: different about withcancel and withtimeout in golang's context
body: <p>I'm new in Golang and I have some confused about <code>WithCancel</code> and <code>WithTimeout</code> when I learn golang's context part. </p>
  
  <p>Show the code. </p>
  
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      "context"
      "fmt"
      "time"
  )
  
  func someHandler() {
      //ctx, cancel := context.WithCancel(context.Background())
      ctx, cancel := context.WithTimeout(context.Background(),  2*time.Second)
      go doSth(ctx)
  
      time.Sleep(3 * time.Second)
      cancel()
  }
  
  func doSth(ctx context.Context) {
      var i = 1
      for {
          time.Sleep(1 * time.Second)
          select {
          case &lt;-ctx.Done():
              fmt.Println("done")
              return
          default:
              fmt.Printf("work %d seconds: \n", i)
          }
          i++
      }
  }
  
  func main() {
      fmt.Println("start...")
      someHandler()
      fmt.Println("end.")
  }
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>// when use WithCancel
  //
  start...
  work 1 seconds: 
  work 2 seconds: 
  end.
  
  // when use WithTimeout
  start...
  work 1 seconds:
  done
  end.
  </code></pre>
  
  <p>My question is: why doesn't it print '<code>done</code>' when I use <code>withCancel</code> but <code>withTimeout</code> does print it?</p>