https://kotlinlang.org logo
Title
y

yougin

04/15/2020, 12:13 PM
Hey guys! Could you think of a better solution for emitting an event with a delay after the first emission from
Observable
?
just(1)
    .flatMap { just(2).delay(1, SECONDS).startWith(it) }
    .subscribe { println(it) }
Just curious if I’m missing on some operator which does the thing.
z

Zach Klippenstein (he/him) [MOD]

04/15/2020, 2:28 PM
I think you could use
andThen
concat
to keep the ordering a little more natural.
y

yougin

04/15/2020, 2:28 PM
isn’t
andThen
for
Completable
only?
z

Zach Klippenstein (he/him) [MOD]

04/15/2020, 3:06 PM
sorry,
concat
y

yougin

04/15/2020, 3:07 PM
that’s a good point, thank you
u

ursus

04/15/2020, 9:55 PM
maybe this? `
Observable.merge(
   source.take(1), 
   source.skip(1).delay(..)
)
just make sure to refcount the source if its cold
y

yougin

04/16/2020, 9:15 AM
thanks, Vlastimil, it looks like an option too.