I have a game where I am creating a pause button. The pause button needs to stop and then resume a specific task:
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: {
if self.ongoing {
self.dispose()
}
})
I was thinking of doing this by keeping track of when this task was scheduled and keeping track of when the pause started so I could then schedule a new task with an updated time after the player unpauses. However, I don't know how to cancel the old task. Is there an easier way of freezing/stopping temporarily a task scheduled by DispatchQueue?