Delay calls using DispatchQueue.asyncAfter [duplicate]

Delay calls using DispatchQueue.asyncAfter [duplicate]



This question already has an answer here:



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?


asyncAfter


DispatchQueue



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.



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






Are you running this in a playground?

– rmaddy
Sep 9 '18 at 21:55






Yes, it's playground. The duplicate link solved the problem. Thanks!

– bvh
Sep 9 '18 at 22:08




1 Answer
1



Are you testing it in a Playground?



If yes try import PlaygroundSupport


import PlaygroundSupport



and set



PlaygroundPage.current.needsIndefiniteExecution = true


PlaygroundPage.current.needsIndefiniteExecution = true



You have to say to the playgroundPage to not stop when the compiler reaches the end of the file but to wait






This was a duplicate. No need to post this answer.

– rmaddy
Sep 9 '18 at 21:57






He didn't say anything about if it's running the code above in a playground. So I can't tell you if it's a duplicate

– ndPPPhz
Sep 9 '18 at 22:02






OK, either your answer is irrelevant (if they are not using a playground) or it's a duplicate (if they are using a playground). So either way there is no need for the answer. If the OP states they are not using a playground then the question can be reopened.

– rmaddy
Sep 9 '18 at 22:05

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ