Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RxJava in a nutshell

RxJava in a nutshell

Alexey Bykov

March 20, 2022
Tweet

More Decks by Alexey Bykov

Other Decks in Technology

Transcript

  1. Alexey Bykov * Google Developer Expert for Android * Android

    Engineer @Revolut * EX: Android Academy MSK community lead * EX: Podlodka Crew & AppsConf
  2. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  3. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } //Ordering?
  4. //Ordering? Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe

    { printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } //Threading?
  5. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  6. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  7. public static <T> Observable<T> just(T item) { ObjectHelper.requireNonNull(item, "item is

    null"); return RxJavaPlugins.onAssembly( new ObservableJust<T>(item) ); } Observable.just("Hey")
  8. Observable.just("Hey") public static <T> Observable<T> just(T item) { ObjectHelper.requireNonNull(item, "item

    is null"); return RxJavaPlugins.onAssembly( new ObservableJust<T>(item) ); }
  9. Observable.just("Hey") public static <T> Observable<T> just(T item) { ObjectHelper.requireNonNull(item, "item

    is null"); return RxJavaPlugins.onAssembly( new ObservableJust<T>(item) ); }
  10. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  11. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  12. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  13. Observable.just("Hey")
 .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Store reference
  14. Observable.just("Hey")
 .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Store reference
  15. Observable.just("Hey")
 .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Store reference Store reference
  16. Observable.just("Hey")
 .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Store reference Store reference
  17. Observable.just("Hey")
 .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Store reference Store reference Store reference
  18. Observable.just("Hey")
 .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Store reference Store reference Store reference Store reference
  19. Observable.just("Hey")
 .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Store reference Store reference Store reference Store reference Store reference
  20. Observable.just("Hey")
 .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Store reference Store reference Store reference Store reference Store reference Store reference
  21. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  22. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  23. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Subscribe
  24. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Subscribe Subscribe
  25. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Subscribe Subscribe //1. Change thread: Computation
  26. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Subscribe Subscribe //1. Change thread: Computation Subscribe
  27. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Subscribe Subscribe //1. Change thread: Computation //2. Execute callback: Computation Subscribe
  28. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Subscribe Subscribe //1. Change thread: Computation //2. Execute callback: Computation Subscribe Subscribe
  29. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length }
 .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Subscribe Subscribe //1. Change thread: Computation //2. Execute callback: Computation Subscribe Subscribe Subscribe
  30. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length }
 .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Subscribe Subscribe //1. Change thread: Computation //2. Execute callback: Computation Subscribe Subscribe Subscribe Subscribe
  31. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length }
 .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Subscribe Subscribe //1. Change thread: Computation //2. Execute callback: Computation Subscribe Subscribe Subscribe Subscribe //3. Change thread: IO
  32. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length }
 .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Subscribe Subscribe //1. Change thread: Computation //2. Execute callback: Computation Subscribe Subscribe Subscribe Subscribe //3. Change thread: IO Subscribe
  33. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  34. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  35. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Emit «Hey», IO
  36. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } Emit «Hey», IO Emit «Hey», IO
  37. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } //1. Print thread, IO Emit «Hey», IO Emit «Hey», IO
  38. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } //1. Print thread, IO Emit «Hey», IO Emit «Hey», IO Emit «Hey», IO
  39. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } //1. Print thread, IO //2. Change thread, Main Emit «Hey», IO Emit «Hey», IO Emit «Hey», IO
  40. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } //1. Print thread, IO //2. Change thread, Main Emit «Hey», IO Emit «Hey», IO Emit «Hey», IO Emit «Hey», Main
  41. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } //1. Print thread, IO //2. Change thread, Main Emit «Hey», IO Emit «Hey», IO Emit «Hey», IO Emit «Hey», Main Emit «Hey», Main
  42. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } //1. Print thread, IO //2. Change thread, Main Emit «Hey», IO Emit «Hey», IO Emit «Hey», IO Emit «Hey», Main Emit «Hey», Main Emit «Hey», Main
  43. Observable.just("Hey") .subscribeOn(Schedulers.io()) .map { printThread() it.length } .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe {

    printThread() } .subscribeOn(Schedulers.computation()) .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() } //1. Print thread, IO //2. Change thread, Main //3. Print thread, Main Emit «Hey», IO Emit «Hey», IO Emit «Hey», IO Emit «Hey», Main Emit «Hey», Main Emit «Hey», Main
  44. Observable.just("Hey") … .observeOn(AndroidSchedulers.mainThread()) … .flatMap { printThread() //Own lifecycle: Creation,

    Subscription, Emission Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  45. Observable.just("Hey") … .observeOn(AndroidSchedulers.mainThread()) … .flatMap { printThread() 1. Creation Observable.timer(1,

    TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  46. Observable.just("Hey") … .observeOn(AndroidSchedulers.mainThread()) … .flatMap { printThread() 2. Subscription Observable.timer(1,

    TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  47. Observable.just("Hey") … .observeOn(AndroidSchedulers.mainThread()) … .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single())

    .doOnSubscribe { printThread() } }.subscribe { printThread() } //1. Print thread, Main //2. Change thread, Single
  48. Observable.just("Hey") … .observeOn(AndroidSchedulers.mainThread()) … .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single())

    .doOnSubscribe { printThread() } }.subscribe { printThread() } //1. Print thread, Main //2. Change thread, Single
  49. public static Observable<Long> timer(long delay, TimeUnit unit) { return timer(delay,

    unit, Schedulers.computation() ); } public static Observable<Long> timer(long delay, TimeUnit unit, Scheduler scheduler) { ObjectHelper.requireNonNull(unit, "unit is null"); ObjectHelper.requireNonNull(scheduler, "scheduler is null"); return RxJavaPlugins.onAssembly( new ObservableTimer(Math.max(delay, 0L), unit, scheduler)); }
  50. Observable.just("Hey") … .observeOn(AndroidSchedulers.mainThread()) … .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single())

    .doOnSubscribe { printThread() } }.subscribe { printThread() } //1. Print thread, Main //2. Change thread, Single //3. Change thread, Computation
  51. Observable.just("Hey") … .observeOn(AndroidSchedulers.mainThread()) … .flatMap { printThread() 3. Emission Observable.timer(1,

    TimeUnit.SECONDS) .subscribeOn(Schedulers.single()) .doOnSubscribe { printThread() } }.subscribe { printThread() }
  52. Observable.just("Hey") … .observeOn(AndroidSchedulers.mainThread()) … .flatMap { printThread() Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.single())

    .doOnSubscribe { printThread() } }.subscribe { //1. Print thread, Computation printThread() } Emit 0, Computation Emit 0, Computation
  53. Builder operators example //1. just //2. fromCallable //3. defer //4.

    interval //5. delay https://reactivex.io/documentation/operators.html etc…
  54. Executable on subscription step //1. subscribeOn //2. startWith //3. doOnSubscribe

    https://reactivex.io/documentation/operators.html etc…
  55. Executable on emission step //1. observeOn //2. doOnNext, doOnError, catch

    //3. *map family https://reactivex.io/documentation/operators.html //4. disctinctUntilChange etc…
  56. Opinion: only latest to the top subscribeOn will be executed

    and applied All subscribeOn will be executed, but latest applied
  57. init { subject.debounce(300, TimeUnit.MILLISECONDS) } .switchMap { getData() } .distinctUntilChanged()

    .observeOn(AndroidSchedullers.mainThread()) .subscribeTillCleared(::setState,::processError)
  58. class LogoutMediator { } private val subject = PublishSubject.create() fun

    logoutRequired() {…} fun observeLogout(): Observable<Unit> = subject
  59. class LogoutMediator { } private val subject = PublishSubject.create() fun

    logoutRequired() {…} fun observeLogout(): Observable<Unit> = subject .toSeriallised()
  60. • class RxTrampolineSchedulerRule : TestRule { • • override fun

    apply(base: Statement, description: Description): Statement { • return object : Statement() { • @Throws(Throwable::class) • override fun evaluate() { • RxJavaPlugins.setIoSchedulerHandler { Schedulers.trampoline() } • RxJavaPlugins.setComputationSchedulerHandler { Schedulers.trampoline() } • RxJavaPlugins.setNewThreadSchedulerHandler { Schedulers.trampoline() } • RxAndroidPlugins.setInitMainThreadSchedulerHandler { Schedulers.trampoline() } • • try { • base.evaluate() • } finally { • RxJavaPlugins.reset() • RxAndroidPlugins.reset() • } • } • } • }
  61. class ViewModel…. init { val disposable = interact.getDog() .observeOn(MainThread()) .subscribe(::processData,::processError)

    } private val compositeDisposable = CompositeDisposable() compositeDisposable.add(disposable)
  62. class ViewModel…. init { val disposable = interact.getDog() .observeOn(MainThread()) .subscribe(::processData,::processError)

    } private val compositeDisposable = CompositeDisposable() compositeDisposable.add(disposable)
  63. Conclusion * RxJava complicated, but you can handle it *

    RxJava won’t disappear soon * New project — Kotlin Coroutines Flow * You need to know it :)