flatMapFirst() operator?

131 views
Skip to first unread message

Habib Okanla

unread,
Mar 8, 2017, 10:13:29 PM3/8/17
to RxJava
Hi,

I found myself needing an operator which would do what FlatMapFirst (https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/flatmapfirst.md) does, but couldn't find anything for RxJava. Is there a good way to reproduce the same behavior?

Thanks and best,

Habib

Dávid Karnok

unread,
Mar 9, 2017, 3:54:39 AM3/9/17
to Habib Okanla, RxJava
Hi. If I understand that document properly (no marble there you see), then you can achieve a similar effect by onBackpressurLatest before flatMap(maxConcurrency = 1):

    Observable.interval(0, 1, TimeUnit.SECONDS)
    .onBackpressureLatest()
    .flatMap(v -> Observable.timer(1900, TimeUnit.MILLISECONDS), 1)
    .take(10)
    .toBlocking()
    .subscribe();

--
Best regards,
David Karnok

Habib Okanla

unread,
Mar 12, 2017, 7:05:03 PM3/12/17
to RxJava, habib....@gmail.com
Outstanding, thanks Dávid! Today learned that flatmap has a concurrency limit parameter!
Reply all
Reply to author
Forward
0 new messages