1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 03:25:03 +03:00
vimr/VimR/Debouncer.swift
2017-02-12 17:21:10 +01:00

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()
}