These are chat archives for ReactiveX/RxJava

20th
Mar 2017
Haris Kljajić
@devharis
Mar 20 2017 08:43
Hm, I'm wrapping three retrofit requests in a zip function, seems like it always returns empty array. Its like it doesn't wait until its finished..
FacilityLocalDataStore: Frodo => [@Observable :: @InClass -> FacilityLocalDataStore :: @Method -> add(facilities='[]')]
FacilityItemLocalDataStore: Frodo => [@Observable :: @InClass -> FacilityItemLocalDataStore :: @Method -> add(facilityItems='[]')]
MediaLocalDataStore: Frodo => [@Observable :: @InClass -> MediaLocalDataStore :: @Method -> add(media='[]')]
Haris Kljajić
@devharis
Mar 20 2017 09:08
return mAssignmentLocalDataStore.query()
            .flatMap(assignments -> assignments == null || assignments.isEmpty() ?
                mAssignmentRemoteDataStore.query()
                    .flatMap(remoteAssignments ->
                        Observable.zip(
                                mFacilityItemRepository.query(),
                                mFacilityRepository.query(),
                                mMediaRepository.query(),
                                mAssignmentLocalDataStore.query(),
                                (remoteEntities, remoteFacilities, remoteMedia, localAssignmentsRetry)
                                        -> localAssignmentsRetry
                        )
                    ) : Observable.just(assignments)
            );
Only the first method in the zip gets its items and inserts them
Rest is being skipped, don't understand why
Haris Kljajić
@devharis
Mar 20 2017 10:43
If the inital method is subscribing and observing on mainThread, are the subsequential method calls within that initial method call forced to have subscribe aswell in order to make it work?
Zak Taccardi
@ZakTaccardi
Mar 20 2017 13:06
If you have 4 observables in a zip, you only get an emission when those 4 observables emit. So if the first 3 emit twice, and the fourth emits once, you'll only get one emission from the zip
Viktor Gal
@vigsterkr
Mar 20 2017 13:21
hi! although i'm trying to use rx in cpp but this is rather a conceptual question: i'd like to create an observable around a socket (websocket name). what should be the best way to do this? extend Subject in order to be able to support both reading and sending...?
Haris Kljajić
@devharis
Mar 20 2017 13:45
So what could be the reason that all observers in the zip returns empty array @ZakTaccardi ?
Zak Taccardi
@ZakTaccardi
Mar 20 2017 13:53
@vigsterkr subjects already support reading and writing. They're the mutable variables of the Rx
world
A subject actually already extends an Observable
@devharis log each step in your stream and you'll find out
Haris Kljajić
@devharis
Mar 20 2017 18:08

Hm, yeah I did using a lib called Frodo. pretty neat..

It seems mAssignmentRemoteDataStore.query()executes correctly adding items to the database, then in the zip mFacilityItemRepository.query(), executes also just fine but mFacilityRepository.query(), and mMediaRepository.query(), just get skipped altho they are called. Its like the zip gets finished after the first call.

There isn't any error, seems just fine
Haris Kljajić
@devharis
Mar 20 2017 18:13
Could it have something to do with this? :D It will only emit as many items as the number of items emitted by the source Observable that emits the fewest items.?
Zak Taccardi
@ZakTaccardi
Mar 20 2017 18:36
yes^^
Haris Kljajić
@devharis
Mar 20 2017 18:36
Thats seems weird, how could that be resolved if this is the case? Can you point me in any direction?
Any operation?
Zak Taccardi
@ZakTaccardi
Mar 20 2017 18:37
within a zip, if query1() emits 5 items, query2() emits 4 items, and query3() emits 1 item, that zip function will only ever run over 1 item
you may want to use Observable.combineLatest() to observe the latest values from those queries
Haris Kljajić
@devharis
Mar 20 2017 18:38
Thanks, I'll look into it!
Zak Taccardi
@ZakTaccardi
Mar 20 2017 18:38
np
Haris Kljajić
@devharis
Mar 20 2017 18:40
Worked like a charm, now I need to learn why xD
Zak Taccardi
@ZakTaccardi
Mar 20 2017 18:41
because whenever one of those 4 queries emits new information, the combineLatest function is run over the latest emitted value from the other 3
DavidMihola
@DavidMihola
Mar 20 2017 18:41
It, as it were, always combines the latest values into a new one. :-)
Haris Kljajić
@devharis
Mar 20 2017 18:42
I really appreciate your help, here's a virtual beer :beer: !
Zak Taccardi
@ZakTaccardi
Mar 20 2017 18:43
cheers!