https://kotlinlang.org logo
#rx
Title
# rx
a

António Bastião

11/14/2019, 3:07 PM
Hi everyone, I’m new with Rx. Can anyone help to understand
requestData()
is called twice and how to avoid it?
Copy code
Observable.just(Unit)
                .delay(REPEAT_DELAY, TimeUnit.MILLISECONDS)
                .repeat()
                .async(job)
                .subscribe({ requestData() },
                        {
                            Timber.e(it, "subscribeError")
                        }
                )
t

tseisel

11/14/2019, 3:20 PM
Where does the
async
function comes from ? I can't resolve it.
a

António Bastião

11/14/2019, 3:38 PM
custom Kotlin extension but thank you. Observe on Schedulers.io() and subscribe on Schedulers.io(). Same thing for asyncUI
but the latter one observe on main thread
t

tseisel

11/14/2019, 4:53 PM
Your problem is due to the
repeat
operator : it will re-emit the same
Unit
undefinitely, every
REPEAT_DELAY
. Maybe you could tell us more about what you want to achieve ?
a

António Bastião

11/14/2019, 5:08 PM
It’s solved. Noob thing. Sorry. Anyway, the repeat is intentional and that’s the expected behavior. The problem was the requestData() to be called twice every time the repeat was executed and not that it repeats per every desired amount of time.