mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-29 00:34:26 +03:00
29 lines
582 B
Swift
29 lines
582 B
Swift
/**
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
* See LICENSE
|
|
*/
|
|
|
|
import Foundation
|
|
import RxSwift
|
|
|
|
class Debouncer<T> {
|
|
|
|
let observable: Observable<T>
|
|
|
|
init(interval: RxTimeInterval) {
|
|
self.observable = self.subject.throttle(interval, latest: true, scheduler: self.scheduler)
|
|
}
|
|
|
|
deinit {
|
|
self.subject.onCompleted()
|
|
}
|
|
|
|
func call(_ element: T) {
|
|
self.subject.onNext(element)
|
|
}
|
|
|
|
fileprivate let subject = PublishSubject<T>()
|
|
fileprivate let scheduler = SerialDispatchQueueScheduler(qos: .userInteractive)
|
|
fileprivate let disposeBag = DisposeBag()
|
|
}
|