title: Flask: stream to jQuery/$.post() from generator with yield
body: <p>I would like to stream chunks of data from a generator in flask after I called the function with jQuery $.post():</p>
  
  <pre><code>@app.route('/some/function', methods=['POST'])
  def calculateSomething():
      def g():        
          # do something here
          yield 'result1'
          # do more ...                
          yield 'result2'     
      return Response(g())
  </code></pre>
  
  <p>I call this function from jQuery:</p>
  
  <pre><code>$.post("/some/function", {"some": $data}, function(data) {
      alert(result)
  })
  </code></pre>
  
  <p>This only gives me one alert saying 'result1result2' and not two separate alerts for each yield. So the callback function is called after everything was 'yielded'. </p>
  
  <p>How can I properly stream to jQuery with yield?</p>