I am using RxJava Interval Like this
compositeDisposable.add( Observable.interval(1, TimeUnit.SECONDS) .flatMap(tick -> { return Observable.just(doWork(tick)); }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(this::updateUI, e -> { disableIndicator(); FirebaseCrashlytics.getInstance().recordException(e); }) ); public Status init(long tick) { // Doing heavy task // Here the Status is an Enum class return output } public void updateUI(Status value) { // Updates UI accordingly }
Everything works as expected, but I have a concern. So my doWork()
method is doing some heavy task in bg and I am updating the UI in updateUI()
method based on the result produced by that method.I am calling the doWork() every second using RxJava Interval. Usually it takes less than a second to execute the doWork()
method. So I was just wondering what happens if I have lots of data and the doWork()
method takes more than one seconds to execute, lets say it takes 2 seconds.But the interval will keep calling the doWork()
method every second. Since my previous execution will take another one second to complete what will I get as return value?
没有评论:
发表评论