Reactive Programming on Android with RxJava



Download 1,47 Mb.
Pdf ko'rish
bet17/60
Sana20.04.2022
Hajmi1,47 Mb.
#566724
1   ...   13   14   15   16   17   18   19   20   ...   60
Bog'liq
reactiveandroid

.subscribe(Consumer onNext)
: only
.onNext()
events are received. All errors
will forward to the
RxJavaPlugins.onError()
handler.

.subscribe(Consumer onNext, Consumer onError)
: only
.onNext()
and
.onError()
events are received and
.onComplete()
is ignored.

.subscribe(Consumer onNext, Consumer onError, Ac-
tion onComplete)
: all events are received.

.subscribe(Consumer onNext, Consumer onError, Ac-
tion onComplete, Consumer onSubscribe)
: all events are received;
additionally, a
Consumer
can be specified to receive the upstream’s
Disposable
object.
Previously in RxJava 1.x, if a method was omitted but called by the
Observable
(e.g. the
.onCom-
plete()
definition was not provided on subscription but called by the
Observable
), an exception
would have been thrown. However, this was changed in RxJava 2 so that you don’t have to provide a
method definition if you are not concerned with certain events. Although the API is more forgiving
now, you should still use an overloaded
.subscribe()
method with caution. In most cases, you
would want to provide an
.onError()
definition and handle the error as appropriate for your use
case.


Chapter 2: RxJava Core Components
17
Push vs. Pull
Looking at the
Observable
and
Observer
definitions, we can see that the design is inherently a
push
based system. An
Observer
will
react
upon receiving an item that was
pushed
to it by the
Observable
that it is subscribed to. However, this does not imply that emitted events are asynchronous. In fact,
by default an
Observable
is synchronous–events will be emitted in the
Observable
stream on the
same thread where
.subscribe()
is invoked.
1
Log
.
d
(
TAG
,
"Creating Observable."
);
2
Observable
.
create
((
ObservableOnSubscribe
<
String
>)
emitter
-> {
3
emitter
.
onNext
(
"test"
);
4
emitter
.
onComplete
();
5
}).
subscribe
(

Download 1,47 Mb.

Do'stlaringiz bilan baham:
1   ...   13   14   15   16   17   18   19   20   ...   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