Skip to content

Instantly share code, notes, and snippets.

@gamako
Created May 20, 2016 23:00
Show Gist options
  • Save gamako/1c52ef8eb19070138fcb35677e696475 to your computer and use it in GitHub Desktop.
Save gamako/1c52ef8eb19070138fcb35677e696475 to your computer and use it in GitHub Desktop.
extension ObservableType {
/**
throttleFirst
RxJava reference
http://reactivex.io/RxJava/javadoc/rx/Observable.html#throttleFirst(long,%20java.util.concurrent.TimeUnit,%20rx.Scheduler)
*/
func throttleFirst(time: RxTimeInterval, scheduler: SchedulerType) -> Observable<E> {
let s = self.share()
return s
.throttle(time, scheduler: scheduler)
.map { _ in () }
.startWith()
.flatMapLatest{ _ in s.take(1) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment