class SessionRepository() : SessionRepositoryInterface { val environment: BehaviorRelay = BehaviorRelay.create() override fun getModules(): Single { //// before getModules is called, set isLoading=true in the view //isLoading.onNext(true) val request = createRetrofit() return request.getModules() .driveOnUI() .onErrorReturn { Module(null, null, null) } .doFinally { //call in the view isLoading.onNext(false) } } }