These are chat archives for ReactiveX/RxJava

19th
Jan 2016
Alexander Shtanko
@AlexanderShtanko
Jan 19 2016 08:41 UTC
Hi! Can you help me? Is there in rxjava repeat operator with condition?
Simon Baslé
@simonbasle
Jan 19 2016 08:42 UTC
hi, what would the condition be on?
there's a repeatWhen variant, but I'm not sure it fits your need
Alexander Shtanko
@AlexanderShtanko
Jan 19 2016 08:44 UTC
repeat operator with simple condition, for example value==true
Simon Baslé
@simonbasle
Jan 19 2016 08:54 UTC
where would the value come from? the problem with repeatWhen is that the repetition is triggered when the source observable completes, so you cannot directly choose to repeat according to a value emitted by said observable
unless your source observable mutates some external synchronized state (like an AtomicBoolean)
also, are you sure you want repeat and not retry?
(I mean, is this a case of really repeating an Observable that completed normally, or the condition could be seen as an error and you want to retry the whole source logic)
Alexander Shtanko
@AlexanderShtanko
Jan 19 2016 09:06 UTC
I want to repeat rest request until I get response with right status
Value come from BehaviorSubject.getValue()
Dorus
@Dorus
Jan 19 2016 09:06 UTC
use retry then.
Alexander Shtanko
@AlexanderShtanko
Jan 19 2016 09:08 UTC
ОK, thanks, I will try
Dorus
@Dorus
Jan 19 2016 09:11 UTC
source.flatMap(e -> BehaviorSubject(...)
.flatMap(e -> {
    if (wrongValue) {
        return Observable.error(...)
    }
    return Observable.just(e);
).retry())
Something among those lines.
Simon Baslé
@simonbasle
Jan 19 2016 09:12 UTC
yep, retry combined with Observable.error would seem a better fit
Alexander Shtanko
@AlexanderShtanko
Jan 19 2016 09:13 UTC
OK)