-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Why resubscribe the source observable emit same output when I use retryWhen operator? #4840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
@akarnokd When I use retrofit & rxjava in project,api return type is Observable,is it a constant Observable?I use cookie in request,and when cookie is invalid,i request new cookie(cookie is a String type member variable) in retrywhen and i got same error from server afterwards because the cookie is old cookie.Why is Observable.just(str) a constant Observabl?Is it because of str's String type?or other reasons?Thanks for your reply. |
Let me illustrate the situation with a classical example program: public class Example {
static String str;
public static void main(String[] args) {
str = "aaa";
String local = str;
str = "ggg";
System.out.println(local);
System.out.println(local);
System.out.println(local);
}
} Can you tell what this program prints to the console? |
@akarnokd I got it.Thanks for your example. |
Great. If you have further input on the issue, don't hesitate to reopen this issue or post a new one. |
@akarnokd |
No. |
@akarnokd okay,it's the same question.groupId is member variable,when i first request from server i set groupid 0 and server return 404.and in retrywhen i changed groupId value,but i find in charles that in Request groupId is 0,too.(Now i use OkHttp interceptor to resolve this problem.But i want to know why groupId didn't change in second retry?) |
How do you call int groupId = 0;
Observable<List<User>> obs1 = groupList(groupId);
groupId = 1;
obs1.subscribe(v -> { }, Throwable::printStackTrace); Do you think the last line will request with |
ApiClient.groupList(groupId)
.map(new Func1<List<User>, List<User>>() {
@Override
public List<User> call(List<User> list) {
if (list.size() == 0) {
throw new RuntimeException("gg");
}
return list;
}
})
.retryWhen(new RetryWithDelay(3, 2000))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<User>>() {
@Override
public void call(List<User> response) {
fillData(response);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
Log.i("===========k3", throwable.toString());
}
}); this is my code.I change groupId in RetryWithDelay's call method.what's wrong with the code? |
You don't seem to understand how a value read from a variable won't change if you change the variable. Use Observable.defer(() -> ApiClient.groupList(groupId))
// ... the rest |
@akarnokd yes,I didn't understand where differences are between Observable.just and Observable.fromCallable.Since you say 'No',I think retrofit's return Observable is like Observable.fromCallable,it is not a constant Observable and it will use fresh value when retry again. |
code:
In my opinion,it should log
but in fact it always log
why?
The text was updated successfully, but these errors were encountered: