0

I've been trying to understand how the asyncAfter method works in DispatchQueue so I could implement it in my code to delay network calls. I've tried the suggestions from this thread to no avail: How do I write dispatch_after GCD in Swift 3 and 4?

In my test code only the first print statement gets printed. How come the second print doesn't print?

func queueWithDelay() {
    let delayQueue = DispatchQueue(label: "testqueue")

    print("First: \(Date())")

    delayQueue.asyncAfter(deadline: .now() + .seconds(1)) {
        print("Second: \(Date())")
    }
}
queueWithDelay()

Thank you in advance.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
bvh
  • 443
  • 4
  • 10

0 Answers0