title: Wait for result without stopping UI
body: <p>I have an iPad app, and I want to do this</p>
  
  <pre><code>-(IBAction) clicked {
      image=download(@"http://....."); // this is on the main thread
  }
  </code></pre>
  
  <p>The download function is going to call a whole bunch of non blocking functions to download a file from the internet, but download itself shouldn't return until the image is downloaded.</p>
  
  <p>While the program is waiting for the download at the image=download(...) line above, I want the UI to be able to still function, for example be able to scroll a UITableView, click another button etc.</p>
  
  <p>So what I did was this inside the download function I used a RunLoop</p>
  
  <pre><code>-(void) download:(NSString *)url 
  {
      BOOL stillDownloading=TRUE;
      while(stillDownloading) {
          stillDownloading=downloadAFwBytes(...);
          CFRunLoopRunInMode(kCFRunLoopCommonModes, 0, YES);
      }
  }
  </code></pre>
  
  <p>I thought the CFRunLoopRunInMode function will keep pumping UI messages, touches, scrolls through the main UI thread so that the UI will keep working and not freeze until the download finished, but for some reason, it only works for a short time, and eventually the UI freezes. </p>
  
  <p>Do you know why, or how to fix? </p>
  
  <p>The download function is called everywhere in the program, that expects it to wait for the download, so I can't change it to non blocking at the moment.</p>