Why resubscribe the source observable emit same output when I use retryWhen operator?
See original GitHub issuecode:
str = "aaa";
Observable.just(str).map(new Func1<String, String>() {
@Override
public String call(String s) {
Log.i("====", "s == " + s);
if ("aaa".equals(s)) throw new RuntimeException(s);
return s + "123";
}
}).retryWhen(new Func1<Observable<? extends Throwable>, Observable<?>>() {
@Override
public Observable<?> call(Observable<? extends Throwable> observable) {
return observable.zipWith(Observable.range(1, 4), new Func2<Throwable, Integer, Integer>() {
@Override
public Integer call(Throwable throwable, Integer i) {
str = "ggg";
return i;
}
}).flatMap(new Func1<Integer, Observable<? extends Long>>() {
@Override
public Observable<? extends Long> call(Integer retryCount) {
return Observable.timer(1, TimeUnit.SECONDS);
}
});
}
}).subscribe(new Action1<String>() {
@Override
public void call(String s) {
Log.i("====k", "s = " + s);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
Log.i("====", "throwable = " + throwable.getMessage());
}
});
In my opinion,it should log
aaa
ggg
ggg
...
but in fact it always log
aaa
aaa
aaa
...
why?
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
RxJava's repeatWhen and retryWhen, explained
The output Observable has to use the input Observable as its source. You must react to the Observable<Throwable> and emit based on it; ......
Read more >why does RxJS retryWhen operator completes with its inner ...
Returns an Observable that mirrors the source Observable with the exception of an error. If the source Observable calls error, ...
Read more >Retry operator - ReactiveX
The retryWhen operator is similar to retry but decides whether or not to resubscribe to and mirror the source Observable by passing the...
Read more >Resubscribe to an Observable on Error with RxJS retry
This is actually an Observable that only has next values. It doesn't have an error. It happens to be that these values are...
Read more >retryWhen - Learn RxJS
import { map, tap, retryWhen, delayWhen } from 'rxjs/operators';. . //emit value every 1s. const source = interval(1000);. const example = source.pipe(.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You don’t seem to understand how a value read from a variable won’t change if you change the variable. Use
defer
:@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. But i was wrong.retrywhen operator’s meaning is resubscribe source Observable,in my code,it is constant because ApiClient.groupList(groupId)) has produced,it is like Observable.just.(I think you should say ‘Yes’ because I think retrofit’s return Observable is like a constant Observable) But when use Observable.defer,the result is different because defer operator decides the Observable is new(use fresh variable) when subscribe. Thanks for your help!love you!