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.