mirror of
https://github.com/yattee/yattee.git
synced 2024-11-15 02:28:23 +00:00
16 lines
341 B
Swift
16 lines
341 B
Swift
|
import Foundation
|
||
|
|
||
|
struct Debounce {
|
||
|
private var timer: Timer?
|
||
|
|
||
|
mutating func debouncing(_ interval: TimeInterval, action: @escaping () -> Void) {
|
||
|
timer = Timer.scheduledTimer(withTimeInterval: interval, repeats: false) { _ in
|
||
|
action()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func invalidate() {
|
||
|
timer?.invalidate()
|
||
|
}
|
||
|
}
|