title: Race-condition while sending http request
body: <p>I have a situation that I need to dispatch two post requests, synchronously, and the second depends on the response of the first, the problem is that the second gets sent even before the first's response is allocated, thus sending wrong information:</p>
  
  <pre><code>update : msg -&gt; model -&gt; (model, Cmd msg)
  update msg m =
      case msg of
  
      ...
  
      Submit -&gt; (m,
          send FirstResp &lt;| post "/resource1"
              (jsonBody &lt;| encoderX m) int)
      FirstResp (Ok x) -&gt; ({m | pid = x},
          send SecondResp &lt;| post "/resource2"
              (jsonBody &lt;| encoderY m) int)
  
      ...
  </code></pre>
  
  <p>I tested it several times. If the server gives <code>3</code> in the first post, the <code>pid</code> gets sent as <code>0</code>, but If I submit it again, the <code>pid</code> is sent as <code>3</code> and the answer from the server, <code>4</code>, for example, is ignored.</p>
  
  <p>How can I make the post to wait for the value to be allocated?</p>