title: How to interrupt an HTTP handler?
body: <p>Say I have a http handler like this:</p>
  
  <pre><code>func ReallyLongFunction(w http.ResponseWriter, r *http.Request) {
          fmt.Fprintf(w, "Hello World!")
          // run code that takes a long time here
          // Executing dd command with cmd.Exec..., etc.
  
  })
  </code></pre>
  
  <p>Is there a way I can interrupt this function if the user refreshes the page or kills the request some other way without running the subsequent code and how would I do it?</p>
  
  <p>I tried doing this:</p>
  
  <pre><code>notify := r.Context().Done()
  go func() {
      &lt;-notify
       println("Client closed the connection")
       s.downloadCleanup()
       return
  }()
  </code></pre>
  
  <p>but the code after whenever I interrupt it still runs anyway.</p>