Timeout for the entire sequence and not individual items

120 views
Skip to first unread message

Kevin GALLARDO

unread,
Jan 17, 2019, 12:00:38 PM1/17/19
to RxJava
Hi all,

Reading the docs about the timeout operator there was a link to the introtorx.com website that explains the timeout operations available. The second example in this doc indicates there is an operator that allows you to define a timeout for the entire sequence and not a timeout between individual items. 

Looking through the Flowable class, it seems the only timeout() methods there are for defining a timeout between items. I am able to make a custom solution with a Flowable.timer() that would accomplish the goal of setting a global timeout for the sequence but I was wondering if a built-in operation like what's mentioned in the introtorx website was at all available on rxJava?

Thanks.

Dávid Karnok

unread,
Jan 17, 2019, 12:06:48 PM1/17/19
to Kevin GALLARDO, RxJava
Hi. You can use takeUntil and specify a total time you want items. You can also use the Observable overload and have a timed sequence fail with TimeoutException if you want.
If you have questions, I recommend asking them on StackOverflow as not many people frequent these groups.
--
Best regards,
David Karnok

Kevin GALLARDO

unread,
Jan 17, 2019, 12:36:49 PM1/17/19
to RxJava
Thanks for the quick answer Dávid.

I think takeUntil will not work as we want an error to be produced if the timeout happens, it seems takeUntil will only return the items emitter before the timeout without error.

I am not sure I understand the second suggestion, would you mind elaborating please?

I also asked on SO, thanks.

Dávid Karnok

unread,
Jan 17, 2019, 12:47:59 PM1/17/19
to Kevin GALLARDO, RxJava
takeUntil(Observable.never().timeout(5, TimeUnit.SECONDS))

Kevin GALLARDO

unread,
Jan 17, 2019, 5:22:46 PM1/17/19
to RxJava
Hey Dávid,

I see, that's a pretty good solution, thanks a lot!
Reply all
Reply to author
Forward
0 new messages