I have in my project Retrofit library and RxAndroid.
For example I've called some method from my api
public void loadSomething() {
getApi().getSomething()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Something>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Something s) {
}
});
}
How should I track progress of this observable for example to prevent user to start it second time? Should add my custom flags something like before start set inProgress = true;
and in all callback methods set inProgress = false;
?
Can I do it with RxAndroid functionality? Or is it guarantee that one call to api will not be started few times in parallel?
You can use the Do operator .
You can set the inPogress = true
in doOnSubscribe()
and inProgress = false
in doOnComplete()
.
Also calling subscribe
returns a Subscription . You can use it to check if the call has finished using isUnsubscribed()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.