Skip to content

Instantly share code, notes, and snippets.

@smhdk
Created December 7, 2018 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smhdk/9e64b78bfa4c93ee843fa58992bf6fc5 to your computer and use it in GitHub Desktop.
Save smhdk/9e64b78bfa4c93ee843fa58992bf6fc5 to your computer and use it in GitHub Desktop.
RxJava CombineLatest Operator Example with Kotlin
val observable1 = Observable.interval(400, TimeUnit.MILLISECONDS)
val observable2 = Observable.interval(250, TimeUnit.MILLISECONDS)
Observable.combineLatest(
observable1,
observable2,
object : BiFunction<Long, Long, String> {
override fun apply(t1: Long, t2: Long): String {
return "observable1 value: $t1 , observable2 value: $t2"
}
})
.take(5)
.subscribe(object : Observer<String> {
override fun onComplete() {
println("onComplete")
}
override fun onSubscribe(d: Disposable) {
println("onSubscribe")
}
override fun onNext(t: String) {
println("onNext: $t")
}
override fun onError(e: Throwable) {
}
})
TimeUnit.SECONDS.sleep(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment