title: DispatchQueue.asyncAfter doesn't work the way I thought it would?
body: <p>I'm working on an application where the 403 forbidden error I tried to debug was actually caused by an upper bound on the amount of requests you can make to an endpoint per minute (silly me).</p>
  
  <p>All good, I decided to throw my network requests onto a DispatchQueue (better concurrent design anyway) and use the asyncAfter(deadline:execute:) function to cause a 4 second delay between each request.</p>
  
  <p>The design of my program is that each item in a list calls a function, and within that function some work (the request) is put onto that dispatch queue. See below:</p>
  
  <pre><code>class ViewController
  
  let serialQueue = DispatchQueue(label: "networkRequests")
  
  func myFirstFunc {
      for item in items {
          self.mySecondFunc(item: item, completionHandler: {(completionItem) in
              // you shouldn't need this
         })
      }
  }
  
  func mySecondFunc(item: someType, completionHandler: @escaping (String?) -&gt; Void) {
  
          let task = session.dataTask(with: request, completionHandler: {(data, response, error) in
              // stuff 
              completionHandler(changedItem)
          })
          self.serialQueue.asyncAfter(deadline: .now() + 4.0) {
                  task.resume()
                  print(Date())
              }
          }
      }
  }
  </code></pre>
  
  <p>The way I thought this would work is regardless of if the function is called by different threads concurrently, the code enclosed in the asyncAfter(deadline:execute:) call would be queued up, and the next closure wouldn't start executing until the last closure had completed and an 4 additional seconds had passed.</p>
  
  <p>This didn't work -- print(Date()) has no delays between the printed times. </p>
  
  <p>I fixed it by using the sleep() function in unix, but I'm curious about how this would work in Swift using GCD.</p>
  
  <p>Thanks!</p>
  
  <p>Edit: Specifically looking for the right way to have functionality where a single thread executes each request such that the thread is blocked until the previous is finished with a 4 second delay in between. </p>