javaandroidrx-javarx-java2rx-java3

adjust delay value in rx java from source


I'm new to Rxjava and could not find an example or appropriate usage of single.delay() that uses the result of the previous flatmap as the delay. My aim is to use the result of functionOne() to set the delay dynamically.

.flatMap(o -> functionOne(para),Pair::new)
.flatMap(pair -> Single.delay(pair.first, TimeUnit.millis))
.doOnSuccess(o -> funcitonTwo(driver, pair.two))

I'm really shooting in the dark but some things I gave a try where; delaySubscription, retryWhen, replayWhen,

I could not get these examples to work.


Solution

  • Delay is for in-sequence delaying. There are a couple of ways for doing this. Given your funcitonTwo usage, you'll probably need this:

    .flatMap(o -> functionOne(para), Pair::new)
    .flatMap(pair -> Single.just(pair).delay(pair.first, TimeUnit.millis))
    .doOnSuccess(pair -> funcitonTwo(driver, pair.two))