title: How to make my function return to Slack right away?
body: <p>I'm trying to develop a simple API for Slack and I want to return something to the user right away to avoid the 3000 ms timeout.</p>
  
  <p>Here are my questions:  </p>
  
  <ol>
  <li><p>Why the <code>This should be printed to Slack first</code> doesn't get printed right away, instead I only got the last message which is <code>The long and blocking process completed</code>? But it appears in ngrok log though.</p></li>
  <li><p>Why is my function still reaching the 3000 ms limit even though I'm already using a go routine? Is it because of the <code>done</code> channel?</p></li>
  </ol>
  
  <pre><code>func testFunc(w http.ResponseWriter, r *http.Request) {
      // Return to the user ASAP to avoid 3000ms timeout.
      // But this doesn't work. Nothing is returned but
      // the message appeared in ngrok log.
      fmt.Fprintln(w, "This should be printed to Slack first!")
  
      // Get the response URL.
      r.ParseForm()
      responseURL := r.FormValue("response_url")
  
      done := make(chan bool)
  
      go func() {
          fmt.Println("Warning! This is a long and blocking process.")
          time.Sleep(5 * time.Second)
  
          done &lt;- true
      }()
  
      // This works! I received this message. But I still reached the 3000ms timeout.
      func(d bool) {
          if d == true {
              payload := map[string]string{"text": "The long and blocking process completed!"}
              j, err := json.Marshal(payload)
  
              if err != nil {
                  w.WriteHeader(http.StatusInternalServerError)
              }
  
              http.Post(responseURL, "application/json", bytes.NewBuffer(j))
          }
      }(&lt;-done)
  }
  </code></pre>