Created
May 28, 2018 18:58
-
-
Save filsv/72158b5c30857ff1b6da60d25dec9bff to your computer and use it in GitHub Desktop.
Cancelable Delay Function - Swift 4.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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