Skip to content

Instantly share code, notes, and snippets.

@smhdk
Last active December 4, 2018 15:25
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/d567989caa965b29ea0a3678b25a1673 to your computer and use it in GitHub Desktop.
Save smhdk/d567989caa965b29ea0a3678b25a1673 to your computer and use it in GitHub Desktop.
RxJava SwitchOnNext Operator with Kotlin
Observable
.switchOnNext(
Observable.interval(100, TimeUnit.MILLISECONDS).map { i ->
Observable.interval(30, TimeUnit.MILLISECONDS).map { i2 -> i }
})
.take(6)
.subscribe(object : Observer<Long> {
override fun onComplete() {
println("onComplete")
}
override fun onSubscribe(d: Disposable) {
println("onSubscribe")
}
override fun onNext(t: Long) {
println("onNext : $t")
}
override fun onError(e: Throwable) {
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment