DispatchTimer

3.0.0

shareup/dispatch-timer

What's New

v3.0.0

2022-11-04T23:55:37Z
  • Increase minimum target and Swift versions
  • Update dependencies

DispatchTimer

DispatchTimer is a GCD-powered timer with a similar API to Timer (née NSTimer). DispatchTimer's big advantage over Timer is it doesn't need a RunLoop to fire, which means you can use DispatchTimer on background threads without any problems. The disadvantage of DispatchTimer is you need to retain a reference to it or it won't fire.

Installation

To use DispatchTimer with the Swift Package Manager, add a dependency to your Package.swift file:

dependencies: [
  .package(url: "https://github.com/shareup/dispatch-timer.git", from: "2.1.2"),
],

Usage

let oneoff = DispatchTimer(.milliseconds(50), block: { print("fired") })

let repeating = DispatchTimer(
  .milliseconds(50),
  repeat: true,
  block: { print("fired") }
)

let fireAt = DispatchTimer(
    fireAt: DispatchTime.now() + .milliseconds(50),
    block: { print("fired") }
)

License

The license for DispatchTimer is the standard MIT license. You can find it in the LICENSE file.

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

Last updated: Thu Nov 10 2022 12:38:50 GMT-0500 (GMT-05:00)