Reactive Programming on Android with RxJava


Marble diagram of .merge()



Download 1,47 Mb.
Pdf ko'rish
bet30/60
Sana20.04.2022
Hajmi1,47 Mb.
#566724
1   ...   26   27   28   29   30   31   32   33   ...   60
Bog'liq
reactiveandroid

Marble diagram of .merge()
Say, for instance, we wanted to combine the results of places recommended by 2 different recom-
mendation engines and merge the results of those two. If each recommendation was encapsulated
in an
Observable
, combining the results of these would be a trivial operation with
.merge()
:
1
Observable
<
Place
>
getNearbyPlacesGoogle
(
Location location
) {
2
// Method that makes a network call to a Google API
3
// to get all nearby places from `location`
4
}
5
6
Observable
<
Place
>
getNearbyPlacesFourSquare
(
Location location
) {
7
// Method that makes a network call to Four Square's API
8
// to get all nearby places from `location`
9
}
Using the two methods defined for retrieving place recommendations, we can combine the results
of each through
.merge()
:


Chapter 3: Operators
36
1
Observable
<
Place
>
allNearbyPlaces
=
Observable
.
merge
(
2
getNearByPlacesGoogle
(
location
),
3
getNearByPlacesFourSquare
(
location
)
4
);
5
allNearbyPlaces
.
subscribe
(
place
-> {
6
// Get all nearby places here
7
});
As soon as an
Observer
subscribes to the
Observable
allNearbyPlaces
, each passed in
Observable
is
individually subscribed to internally in
.merge()
and the result is then
merged
and combined. Note
that from the marble diagram of
.merge()
, the resulting emissions can be interleaved, and once an
.onComplete()
is received from an
Observable
, the merged
Observable
completes as well. If the
interleaving behavior is undesired, the
.concat() Operator
may be used to
concatenate
the results
rather than
merge
them. In effect, the passed in
Observable
instances are subscribed to serially
as each one completes rather than simultaneously. If the preceding
Observable
does not complete
however (i.e. an infinite stream), the subsequent
Observable
will not be subscribed to.

Download 1,47 Mb.

Do'stlaringiz bilan baham:
1   ...   26   27   28   29   30   31   32   33   ...   60




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish