Skip to content

Instantly share code, notes, and snippets.

@amanshuraikwar
Last active December 30, 2018 15:47
Show Gist options
  • Save amanshuraikwar/e584d79f40aac6ba2a191545de5c2ace to your computer and use it in GitHub Desktop.
Save amanshuraikwar/e584d79f40aac6ba2a191545de5c2ace to your computer and use it in GitHub Desktop.
RxJava Thread Switching like a Pro - Medium Article - 1
/*
* 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