title: Consistency of DispatchTime.asyncafter
body: <p>In my iPad app I am trying to get a tableView to scroll at pre-determined intervals. To do this I have created a piece of code that creates a closure for each scroll. However the closure is executed seconds later than when I wanted. Here is a simplified Playground which exemplifies the same problem.</p>
  
  <pre><code>import UIKit
  import PlaygroundSupport
  PlaygroundPage.current.needsIndefiniteExecution = true
  
  // Intervals at which the delayed closures should run
  var lengths: [Double] = [0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 
      12.0, 14.0, 16.0, 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0]
  var times: [UInt64] = []
  
  let dispatchStartTime = DispatchTime.now()
  
  for index in 0 ..&lt; lengths.count
  {
      let delayNanoSeconds = Int(lengths[index] * 1_000_000_000)
      let dispatchLength = dispatchStartTime + .nanoseconds(delayNanoSeconds)
      times.append(dispatchLength.rawValue)
  
      DispatchQueue.main.asyncAfter(deadline: dispatchLength)
      {
          let delay = Double(DispatchTime.now().rawValue - times[index])
          print(delay/1_000_000_000)
      }
  }
  </code></pre>
  
  <p>Upon running this I received the following results: (similar results for other trials, and for the code running in my app)</p>
  
  <pre><code>0.01646185
  0.190259978
  0.000302805
  0.59319351
  0.732933723
  0.938841374
  1.08249717
  1.326286228
  8.6309e-05
  0.00019526
  0.000104861
  2.19584049
  0.196220036
  2.000116042
  0.000425943
  0.000202886
  </code></pre>
  
  <p>I can tolerate an error of 50-100 ms. However from the results we can see that the error can be greater than 2 seconds, and it appears to grow with time/amount of closures. In my app there can be on the order of 100 of such intervals. Is it possible to achieve this level of specificity with asyncAfter or would an alternative such as one thread with a busy wait be a better solution?</p>