Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cancelable Delay Function - Swift 4.0
class DelayHelper {
private var cancelled = false
static func run(delay: Double, closure: @escaping () -> ()) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
if !self.cancelled {
closure()
}
}
}
static func cancel() {
cancelled = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment