title: How to wait for callback function return?
body: <p>I have the following code:</p>
  
  <pre><code>http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    player.Exec(command, func(response map[string]interface{}){
      if response["statusCode"]==float64(0) { // ok
        w.Write([]byte(response["statusMessage"].(string)))
        player.SendMessage("&lt;b&gt;"+response["statusMessage"].(string)+"&lt;/b&gt;")
        fmt.Println("playerExec: "+time.Now().Format("20060102150405"))
      } else { // failed to process
        w.WriteHeader(http.StatusBadRequest) // 400
        w.Write([]byte(response["statusMessage"].(string)))
        player.SendMessage(response["statusMessage"].(string))
      }
    })
    // Time.Sleep(Time.Seconds*2)
    fmt.Println("cmd: "+time.Now().Format("20060102150405"))   
  })
  </code></pre>
  
  <p>processing of <code>player.Exec()</code> takes some time (since it initiates WebSocket connection), so the callback function is called after some time (see proofs below). It is late, so I see the following error:</p>
  
  <blockquote>
    <p>http: superfluous response.WriteHeader call from main.main.func1.1</p>
  </blockquote>
  
  <p>Also, when I open the '/' page in the browser, I see no content. 
  If I add <code>Time.Sleep()</code> to my code (see the commented line), then I see the content.
  The Exec() code is <a href="https://github.com/Sandertv/mcwss/blob/master/player.go#L133" rel="nofollow noreferrer">here</a>.</p>
  
  <p>The log shows the following - </p>
  
  <pre><code>cmd: 20200612192659
  playerExec: 20200612192659
  </code></pre>
  
  <p>Is there any way to wait for the callback function return?</p>