0
votes

I have a code block may like this.

fun main() {
    foo()
            .flatMap {
                bar()
            }
            .subscribe({}, {
                main()
            },{
                main()
            })
}

fun foo(): Observable<Int> {
    // has some real business which take times here
    return Observable.just(1)
}

fun bar(): Observable<Int> {
    // has some real business which take times here
    return Observable.just(2)
}

Which will repeat after onComplete or onError.

But I think the style above is not good! Is any good way to this in RxJava itself?

1
What's wrong with retry() and repeat()?akarnokd
Sorry, my mistake to repeat...user3875388

1 Answers

1
votes

Try to apply retry and repeat:

foo()
.flatMap {
     bar()
}
.retry()           // <------------------------------------------
.repeat()
.subscribe({}, {
    // never fails
},{
    // never ends
})