Skip to content

Instantly share code, notes, and snippets.

@filsv
Created May 28, 2018 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filsv/72158b5c30857ff1b6da60d25dec9bff to your computer and use it in GitHub Desktop.
Save filsv/72158b5c30857ff1b6da60d25dec9bff to your computer and use it in GitHub Desktop.
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