Last active
December 30, 2018 15:47
-
-
Save amanshuraikwar/e584d79f40aac6ba2a191545de5c2ace to your computer and use it in GitHub Desktop.
RxJava Thread Switching like a Pro - Medium Article - 1
This file contains hidden or 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
/* | |
* RxJava without any multi-threading | |
*/ | |
println("Calling function : ${Thread.currentThread().id}") | |
val obs = Observable | |
.just(1) | |
.doOnNext { | |
println("OnNext : Val = $it : Thread = ${Thread.currentThread().id}") | |
} | |
.map { | |
println("Map : Val = $it : Thread = ${Thread.currentThread().id}") | |
2 | |
} | |
.doOnSubscribe { | |
println("OnSubscribe : Thread = ${Thread.currentThread().id}") | |
} | |
.doOnNext { | |
println("OnNext : Val = $it : Thread = ${Thread.currentThread().id}") | |
} | |
val thread = Thread { | |
println("Calling thread : Thread = ${Thread.currentThread().id}") | |
obs.subscribe() | |
} | |
thread.start() | |
/* | |
* End | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment