title: Stop goroutine execution on timeout
body: <p>I want to stop goroutine execution on timeout. But it seems like it is not working for me. I am using <code>iris</code> framework.</p>
  
  <pre><code>  type Response struct {
      data   interface{}
      status bool
    }
  
    func (s *CicService) Find() (interface{}, bool) {
  
      ch := make(chan Response, 1)
  
      go func() {
        time.Sleep(10 * time.Second)
  
        fmt.Println("test")
        fmt.Println("test1")
  
        ch &lt;- Response{data: "data", status: true}
      }()
  
      select {
      case &lt;-ch:
        fmt.Println("Read from ch")
        res := &lt;-ch
        return res.data, res.status
      case &lt;-time.After(50 * time.Millisecond):
        return "Timed out", false
      }
  
    }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code> Timed out
   test
   test1
  </code></pre>
  
  <p>Expected Output:</p>
  
  <pre><code> Timed out
  </code></pre>
  
  <p>Can somebody point out what is missing here? It does timeout but still runs goroutine to print <code>test</code> and <code>test1</code>. I just want to stop the execution of goroutine as soon as there is timeout.</p>