A lightweight, modern Swift async/await timer/debounce/throttle implementation for Apple platforms.
- ✅ Swift Concurrency - Built with Swift's modern concurrency model using async/await and actors
- ✅ Thread Safety - Actor-based design ensures thread-safe operation
- ✅ Lightweight - Zero dependencies, minimal footprint
- ✅ Timer Utilities - Built-in
AsyncTimerwith support for one-time and repeating timers with configurable intervals - ✅ Debounce Utilities - Built-in
AsyncDebouncerwith configurable debounce time - ✅ Throttle Utilities - Built-in
AsyncThrottlerwith leading/trailing and drift/anti-drift cadence
- Swift 5.10+ / Swift 6.0
- iOS 13.0+
- macOS 10.15+
- macCatalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
- visionOS 1.0+
Add AsyncTimer to your project using Swift Package Manager by adding it to your Package.swift file's dependencies:
dependencies:[.package(url:"https://github.com/codingiran/AsyncTimer.git", from:"0.0.7")]Or add it directly in Xcode:
- Go to File > Add Packages...
- Enter the repository URL:
https://github.com/codingiran/AsyncTimer.git - Select the version or branch you want to use
import AsyncTimer
// One-time
letonce=AsyncTimer(interval:.seconds(1), repeating:false){print("fire once")}await once.start()
// Repeating (fire immediately on start)
letrepeating=AsyncTimer(interval:.seconds(0.5), repeating:true, firesImmediately:true){print("tick")}await repeating.start()
// ... later
await repeating.stop()import AsyncTimer
letthrottler=AsyncThrottler(
throttleTime:.seconds(0.2),
behavior:.trailingOnly, // .leadingOnly / .leadingAndTrailing
cadence:.antiDrift // .drift for rolling windows
)
// High-frequency calls → at most one execution per window
await throttler.call{print("work")}import AsyncTimer
letdebouncer=AsyncDebouncer(debounceTime:.seconds(0.2))await debouncer.call{print("fire after quiet period")}Contributions are welcome! If you find a bug or have a feature request, please open an issue. If you'd like to contribute code, please fork the repository and submit a pull request.
AsyncTimer is available under the MIT license. See the LICENSE file for more info.