These are chat archives for ReactiveX/RxJava

24th
Jul 2015
Dries De Smet
@Busata
Jul 24 2015 12:28
hi, if I have an observable.from(listwithintegers).flatmap(new func1<Integer,SomeOtherClass>{ ... CODE ... }), and I want the code in flatmap to be executed in parallel since the ...CODE... blocks, why can't I just add a subscribeonscheduler on the flatmap? it works if the code is Observable.just(integer).map(blocking code).subscribeon, but not in the flatmap itself
Dries De Smet
@Busata
Jul 24 2015 12:49
https://gist.github.com/Busata/ccd000ff6426a9cdb4d3 eg, this, is it possible to let the flatmap run in parallel? (with that code it doesn't)
David Stemmer
@weefbellington
Jul 24 2015 13:56
@dstepanov are you using RxJava or another ReactiveX library? If you're using RxJava, maybe you could try (.onErrorResumeNext)
@dstepanov the input to the .onErrorResumeNext would be a function that unwraps the Exception and returns a new Observable, which you would create with Observable.error(unwrappedException)
David Stemmer
@weefbellington
Jul 24 2015 14:07
@Busata I could be wrong but the way I read this is that when .subscribe is called it will execute the flatmap code on a computation worker thread, and that worker thread will block each time Thread.sleep is called
in other words, the observable code will be running on a worker thread, but the code in flatmap will be serialized, not parallelized
AFAIK there used to be a .parallel operator in RxJava but they removed it because its behavior was confusing
what I might try (and I'm not sure if this is the right approach) is using Schedulers.trampoline to schedule some work in the flatmap function, and then return thread execution to the original Schedulers.io thread
David Stemmer
@weefbellington
Jul 24 2015 14:15
.flatMap(new Func1<Integer, Observable<Hotel>>() {
    @Override
        public Observable<Hotel> call(Integer coordinate) {
            Schedulers.trampoline().createWorker().schedule(new Action0() {
                 // ...your code here...
            });
        }
})
it's similar to the problem I posted above
Pavel Meledin
@btbvoy
Jul 24 2015 14:27
How to build Rx* application that will be ready:
  1. To scale on multiple machines? How to manage parallel execution of requests inside cluster of machines? How to split request processing between nodes in cluster?
  2. How to calculate amount of used resource and bandwidth of single node. In order to have some kind of flat progress bar that will indicate that 78 of 100% is used and approximately 20-70 extra requests certain node can handle and later we need to put extra node into cluster?
David Stemmer
@weefbellington
Jul 24 2015 14:30
@Busata that might be tricky because you need to return an Observable though...you could also try:
.flatMap(new Func1<Integer, Observable<Hotel>>() {
    @Override
        public Observable<Hotel> call(Integer coordinate) {
            return Observable.just(coordinate)
                .map(new Func1<Integer, Hotel>() {
                    @Override
                    public Hotel call(Integer coordinate) {
                        // ...your code here...
                    }
                }
                .subscribeOn(Schedulers.io);
            });
        }
})
inlining this crap is so ugly, ugh
Denis Stepanov
@dstepanov
Jul 24 2015 14:56
@weefbellington Thanks! that actually works!
David Stemmer
@weefbellington
Jul 24 2015 14:56
@dstepanov which one lol
Denis Stepanov
@dstepanov
Jul 24 2015 14:57
.onErrorResumeNext(e -> Observable.error(e.getCause())) ;)
David Stemmer
@weefbellington
Jul 24 2015 14:57
spoiled Java 8 people with your lambdas
Matt Langston
@mattblang
Jul 24 2015 15:51
@weefbellington Haha, I know right. (on Android Java 7 here)
Dmitriy Tarasevich
@darussian
Jul 24 2015 15:55
the struggle is real..
David Stemmer
@weefbellington
Jul 24 2015 16:04
is anybody here using Retrolambda (specifically, gradle-retrolambda) in a production Android app?
MightySeal
@MightySeal
Jul 24 2015 16:15
@weefbellington nope. Waiting for kotlin's incermental compilation instead =)
Matt Langston
@mattblang
Jul 24 2015 16:27
@weefbellington I know Dan Lew mentioned on the Fragmented podcast that he uses it in production. I haven’t been brave enough yet.