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

oday

12/08/2020, 12:29 PM
there
Copy code
Observable.interval(2000, TimeUnit.MILLISECONDS)
                .repeatUntil {
                    System.currentTimeMillis() - startTime > 10000
                    true
                }
                .subscribe {
                    purchaseFlowStore
                        .getTransaction(transactionId)
                        .viewModelSubscription({
                            when (it.state) {
                                "done", "authorized" -> {
                                    getOrder()
                                }
                                "error" -> {
                                    showErrorDialog()
                                }
                            }
                        }, {
                            showErrorDialog()
                        })
                }
m

myanmarking

12/09/2020, 12:09 PM
you are doing it wrong. That way, you will get multiple subscriptions active. And the first emission will be delayed 2s
try this
Copy code
class RxTest {
    private val count = AtomicInteger(0)
    private fun getEndpointValue(): Observable<Int>{
        return Observable.just(count.getAndIncrement())
    }


    @Test
    fun `test interval` () {
        Assert.assertEquals(
            Observable.interval(0, 1, TimeUnit.SECONDS)
                .switchMap { getEndpointValue() }
                .filter { value -> value == 5 }
                .take(1)
                .blockingFirst(),
            5
        )
    }
}
👍🏻 1
6 Views