title: Using NSThread sleep in an NSOperation
body: <p>Working with some code, I'm coming across run loops, which I'm new to, inside <code>NSOperation</code>s.</p>
  
  <p>The <code>NSOperation</code>s are busy downloading data - and whilst they are busy, there is code to wait for the downloads to complete, in the form of <code>NSRunLoop</code>s and thread sleeping.</p>
  
  <p>This code in particular is of interest to me:</p>
  
  <pre><code>while (aCertainConditionIsTrue &amp;&amp; [self isCancelled]==NO) {
       if(![[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:1.0]]){
          [NSThread sleepForTimeInterval:1.0];
       }
  }
  </code></pre>
  
  <p>I've read about the run loops, and <code>runMode:beforeDate:</code> will wait for an input source or a timeout. Although I'm not 100% what counts as an input souce.</p>
  
  <p>On the first execution of this it always returns NO and hits the <code>sleepForTimeInterval:</code>. Is this bad?</p>
  
  <p>In a particular utility class, it's hitting the <code>sleepForTimeInterval:</code> a lot - once for each thread - which significantly hurts the performance.</p>
  
  <p>Any better solutions for this, or advice?</p>