Created
December 7, 2018 06:24
-
-
Save smhdk/9e64b78bfa4c93ee843fa58992bf6fc5 to your computer and use it in GitHub Desktop.
RxJava CombineLatest Operator Example with Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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