Hi friends! is this a good place for any (beginner...
# rx
s
Hi friends! is this a good place for any (beginner level) RxJava questions, or is it more meant for RxKotlin specific things? Anyway, I have a question. I have a
Flowable
and I would like to consume all events from it, but add a little delay between each events. How would I best do that?
Oh, this works I guess?
Copy code
theFlowable.concatMap(s -> Flowable.just(s).delay(1, TimeUnit.SECONDS))
k
that is the same as saying:
Copy code
theFlowable.delay(1, TimeUnit.SECONDS)
s
Hm, no? I tried this:
Copy code
Flowable.just("One", "two", "three")
    .delay(1, TimeUnit.SECONDS)
    .subscribe(System.out::println);
I’m getting a one second delay, then all three printing at the same time. This, however:
Copy code
Flowable.just("One", "two", "three")
    .concatMap(f -> Flowable.just(f).delay(1, TimeUnit.SECONDS))
    .subscribe(System.out::println);
..gives me one second pause, “One”, one second pause, “two”, one second pause, “three” – which is what I want.
a
yeah I don't think @kioba is correct - there may be some overload of
delay
that works the way you'd expect it to but in general I think you've got the right approach. You could also
zip
your flowable with
Flowable.interval
to effectively pair up each item in your stream with the item emitted by
interval
. Six to half a dozen though really
s
Allright! Thanks 🙏
k
sorry, you were right, I was thinking about creating a gap for each element from the initial trigger.
concatMap with a delay
is a nice solution!
🙏 1
👍 1