Skip to content

Instantly share code, notes, and snippets.

@nanoxd
Created March 30, 2019 21:55
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 nanoxd/e524058c8248a55c62a999ee3211cdbe to your computer and use it in GitHub Desktop.
Save nanoxd/e524058c8248a55c62a999ee3211cdbe to your computer and use it in GitHub Desktop.
A wrapper around a repeating timer that does not require invalidation.
/// A wrapper around a repeating timer that does not require invalidation.
final class Pendulum {
let timer: Timer
init(seconds: TimeInterval, closure: @escaping () -> ()) {
timer = Timer.scheduledTimer(
withTimeInterval: seconds,
repeats: true,
block: { _ in
closure();
})
}
deinit {
timer.invalidate()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment