https://kotlinlang.org logo
Title
s

Simon Kågedal Reimer

12/10/2019, 3:12 PM
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?
theFlowable.concatMap(s -> Flowable.just(s).delay(1, TimeUnit.SECONDS))
k

kioba

12/10/2019, 4:15 PM
that is the same as saying:
theFlowable.delay(1, TimeUnit.SECONDS)
s

Simon Kågedal Reimer

12/10/2019, 5:57 PM
Hm, no? I tried this:
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:
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

alexsullivan114

12/10/2019, 6:09 PM
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

Simon Kågedal Reimer

12/10/2019, 7:05 PM
Allright! Thanks 🙏
k

kioba

12/10/2019, 8:18 PM
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