title: Sapper server route res.end not sending response until 'get' function completes
body: <p>I ran into a problem while writing a Sapper application, so some familiarity with it will probably be helpful in answering...though the problem may also be polka (like express)...I'm not sure.  That's why I'm here :-)</p>
  
  <p>Here is a simplified example of a problem I ran into, and am trying to understand why.  It is code for a Sapper server route which returns some JSON.</p>
  
  <pre><code>export function get(req, res) {
          let arr = [];
          let count = 0;
          let data = {"somekey": "someval"}
          res.writeHead(200, { 'Content-Type': 'application/json' });
          res.end(JSON.stringify(data));
  
          console.log('response sent');
  
          while (count++ &lt; 1000000000) {
            arr.push(Math.random());
            arr.pop();
          }
  
          console.log(arr[arr.length - 1]);
  }
  </code></pre>
  
  <p>I expect this code to:</p>
  
  <ol>
  <li>Send the stringified JSON to the client</li>
  <li>Console log 'response sent' on the server</li>
  <li>After the while loop completes, console log the last element of the array on the server.</li>
  </ol>
  
  <p>Instead, it console logs 'response sent' on the server, but the client hangs and the server doesn't send the response until the while loop completes.</p>
  
  <p>I thought res.end should send the response as soon as it gets to res.end, but instead it appears to move on through, and only returns the response once the 'get' function completes.</p>
  
  <p>Why is that?  Is it Sapper, Polka or my own misunderstanding of how res.end works?</p>