These are chat archives for ReactiveX/RxJava

9th
Nov 2015
Henry Tao
@henrytao-me
Nov 09 2015 02:09
I have question: can we make throwable optional? Check out this code
Observable.just(true)
  .subscribe(object - > {    

  }, throwable - > {});
Artem Zinnatullin :slowpoke:
@artem-zinnatullin
Nov 09 2015 02:10
What do you mean by "optional"?
Henry Tao
@henrytao-me
Nov 09 2015 02:11
I have to set blank throwable in every subscription. If I don't do it, the app will be crashed if their are some exceptions inside subscription.
Artem Zinnatullin :slowpoke:
@artem-zinnatullin
Nov 09 2015 02:12
sure
it's normal behavior
if you won't react on errors you'll leave the app in unknown state
Dorus
@Dorus
Nov 09 2015 09:54
There are also a couple operators that deal with exceptions: https://github.com/ReactiveX/RxJava/wiki/Error-Handling-Operators
However, ignoring them all-together is bad practice, just like it's a bad idea to not use try...catch in normal code.
fAns1k
@fAns1k
Nov 09 2015 09:56
@Dorus could you help me please? )
I need to resubscribe to replaySubject every time when i get item from another stream
Dorus
@Dorus
Nov 09 2015 09:57
Should be a simple flatMap i think.
flatMap(e -> replaySubject)
fAns1k
@fAns1k
Nov 09 2015 09:58
i think i’ve tried this one
.flatMap(e-> replaySubject.toList())
Dorus
@Dorus
Nov 09 2015 09:58
why toList?
fAns1k
@fAns1k
Nov 09 2015 09:59
in replaySubject i have strings and when i got some item from another stream i have to check is it contains in that replaySubject
Dorus
@Dorus
Nov 09 2015 10:01
ooh, well you can do zip and then filter on left == right.
lemme think
fAns1k
@fAns1k
Nov 09 2015 10:02
zip will waiting for item from both streams (
Dorus
@Dorus
Nov 09 2015 10:02
flatMap(e -> replaySubject.filter(e2 -> e == e2).map(e2 -> e))
Actually we dont need the last map as e == e2 already
fAns1k
@fAns1k
Nov 09 2015 10:03
where i can find where function? is external one?
Dorus
@Dorus
Nov 09 2015 10:04
in Rx.Net, use filter here ;)
fAns1k
@fAns1k
Nov 09 2015 10:06
i will try, thanks
i tried this code
.withLatestFrom(textSubject
                        .asObservable()
                        .replay()
                        .toList()
Dorus
@Dorus
Nov 09 2015 10:11
flatMap(e -> replaySubject.filter(e2 -> e == e2).take(1)) might be even faster.
fAns1k
@fAns1k
Nov 09 2015 10:12
less wrapped objects - yes, but the main question is - would replaySubject filter on current elements in stream)
e.g. from first stream we get element and textSubject has 10 elements - and then filter
and then we get another element from first stream and textSubject has 30 elements
Dorus
@Dorus
Nov 09 2015 10:15
mm, if you do not close the replaySubect, it will even keep emitting on the first item.
might need to close it, but if it's not closed you can't do toList() either right?
So i was assuming it was already completed
fAns1k
@fAns1k
Nov 09 2015 10:16
right it can’t do toList until it closed
Dorus
@Dorus
Nov 09 2015 10:16
My solution has the same problem, it will work but you keep hoarding replaySubject subscriptions for every filtered element
fAns1k
@fAns1k
Nov 09 2015 10:17
not, it will not closed until unsubscribe
so it’s a problem here )
Dorus
@Dorus
Nov 09 2015 10:20
Perhaps you can do something with takeUntil on the replaySubject and close it after a short delay.
fAns1k
@fAns1k
Nov 09 2015 10:20
i thought around this code also
.map(e -> {
textSubject.forEach()...
})
Dorus
@Dorus
Nov 09 2015 10:22
Either takeUntil or takeWhileshould allow that, i'm not sure what is the best way for that in RxJava.
textSubject.asObservable().replay().takeWhile(e -> currentTime < targetTime)
Another option is to put all elements from one stream in a list with scan and use replay(1).take(1)
Dorus
@Dorus
Nov 09 2015 10:27
(do use a threadsafe collection)
fAns1k
@fAns1k
Nov 09 2015 10:29
there is no need subject in this case i think )
we can just put all needed string in threadsafe collection
Dorus
@Dorus
Nov 09 2015 10:30
yup
fAns1k
@fAns1k
Nov 09 2015 10:30
=)
here is the case where rx is not working (
Dorus
@Dorus
Nov 09 2015 10:31
Then it's simply source.filter(e -> collection.contains(e))
fAns1k
@fAns1k
Nov 09 2015 10:32
it’s not so simple=) i have to use e’s fields
that’s why i planned to use toList
Dorus
@Dorus
Nov 09 2015 10:33
source.filter(e -> collection.contains(e.field1)) :)
fAns1k
@fAns1k
Nov 09 2015 10:35
could be )
thanks you i will try it all=)