0

What is difference between

DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
    performTask()
}

and

Thread.sleep(forTimeInterval: 1)
performTask()
  • 1
    I think this answers your question: https://stackoverflow.com/a/32696605/10564881 The short answer is that `DispatchQueue.main.asyncAfter` does not block the thread from doing other work, meanwhile `Thread.sleep` blocks the thread – Răzvan Rujoiu Apr 29 '21 at 05:09
  • Unlike `asyncAfter` `sleep` blocks the current thread. if *delay a function call* is an attempt to make an asynchronous task synchronous don't use any of them. – vadian Apr 29 '21 at 05:10

0 Answers0