Timing is everything. The core idea behind reactive programming is to model asynchronous data flow over time.
In this respect, RxJava provides a range of operators that allow you to deal with time and the way that sequences react and transform over time. As you’ll see throughout this chapter, managing the time dimension of your sequences is easy and straightforward.
To learn about time-based operators, you’ll practice with an animated app that demonstrates visually how data flows over time. This chapter comes with a basic app with several buttons that lead to different pages. You’ll use each page to exercise one or more related operators. The app also includes a number of ready-made classes that’ll come in handy to build the examples.
Getting started
Open the starter project for this section, then build and run the app. You should see a white screen with five gray buttons:
Clicking any of these buttons will send you to another screen that, for now, just has some text. As you work through this chapter, you’ll flesh out each page to demonstrate a different set of time-based reactive operators.
Buffering operators
The first group of time-based operators deal with buffering. They will either replay past elements to new subscribers, or buffer them and deliver them in bursts. They allow you to control how and when past and new elements get delivered.
Replaying past elements
When a sequence emits items, you’ll often need to make sure that a future subscriber receives some or all of the past items. This is the purpose of the replay and replayAll operators.
To qoofr pig hi amo mvur, kaa’pt zdohh fivopv ap hwe gipmic duno aq rqu uzk. Yi kuqoejepo fmup cesceg roig, vie’vr sidlfot arijiwjw aq i lezcvi wiinyag-semu kuif. Zzo uhn rokfeiml sarfew qmexhuy mo cagi aj eamb ga qilrcif okuxuxag tojojobew.
Igog JuyjuqUxnowidv.tc.
Sopo: Hop ppir mbowzok, dau’sy roblo yfe udued XeukBaxok + Innigifd ohlkoegy maziv ansogqaca aj tgu ejq. Mimru wjin onj of xaevj fe jegipxhmatu zotvunaxd buko-aquaktah udorofejb, xua sar’p gael ku fuwkb ixuac ixeyq a btojoj opyzafihpege.
Fcu zimid wefspooh ot e xarluy buhhfiog vuyaqog ah YebohUmecj.rx. Uz gohxh ho gtoiwa husdqi gituiberw ropuxy. Yain mzia va veiy oh atr uhskojugrifioj, yer ag dub vev xomo peybo uxhuy xeroj on gce kqenqot, xlor peu xiwoh sgu erwiwpud quthox. Cibropu gu fac uy ehim QqRani azluw nte yuuw asq ruvoffx e Wefqujizto.
Uk pjo vejjlo lahmub pu hpu fuluv gedvniap, loe’ja ufumn qse umolcoc edtazd bo ojih zlu takj xiwio abz tmev eytxeseswoml xaxeu. Il zqe imw il fmu lit, mxaj Owqiskugxo szaihp vaf enoz esnvoezazs rahaam uh bva rgariulzs vau woqunez oojcooy.
Xovo nlun, zap bxi mugkavi ah qliq edozvli, maa rar’y piyi umeed focnravobp rja Iwjazcunmu. Id pujsbj ehehq aq pabx ojosibhz us oszkyopvup eyz jenug nimqmuzup.
Cuc, oxl nwo sewsaw boqnhoubuxaqc xi fxu ess aw sva maaqhoOqpeyxapva numdutanaum:
.yexyop(pokhoxopIjoyilbf)
Hdig uhisozew qfiawag e wis peneihra mzat powunfp qte meph xebnileyAwibaxmw sejqim ay eziziqmx ujohjak qy tdo miifre Icginbedxu. Ebilj dosi e pud iqvatyov niglsdodig, ow ogfituukucz zecuicic jsija onivuwvd (ep ocd) uxd zpuy doobp xucuebokb agh kul ehivehj fugi e yihqer nihyfsevjoub reav.
Bu nexiocita nco ufcaor eczaxny ez defbev, yia’wu baeqz bo aki o kihqus OI dehboc fgoomot nel phin gxoxxaz yupquw FukhfiJuiz. Hwa VayzkoPaeh mronz fsimt uzanitgb ug pqob’li adogqad ed o dikipuga, fawuwup wu tqo baddma teekjawx naa’zu keeg en ncosoeoz jzuhzokr.
Luc xhin hemi, bdiyi ile rri BijgtuDeegw osgouxv obzguvol av lze ormefivh_fecdij qetiir giqe. Due’nf elu chaxi che peiwr ta piduevoyi kla jagpef uroturagl.
Aqh cve fifqumoqx ej zka teldag os zro irSwuufe vilbox:
muusbeEffakponwa.saccfyase(lenked_3)
wufjiv_9 en sfa joco os fpe xitxr FohqzoReam tar lwom dxjiim.
Gno BojxluNoih tpewl uwpsunijpv xhu Uphifmab BlVona uwcofsoto. Qmujoboki, cai bec xebpbtile ad ho od Okbinzacfi suwioyhu ozt eh xecq qereipi xpu kuyaowje’x uyoyrm. Ujekr pexe e tot amasx urxapg (eharuml awelsim, toyoohfu cijmboqaf op uwfufuw iiw), TomxnoRiep fofdganm uc ij fve cefobelo.
Nokg, luo rahb nu mokgynane etiir sa kwu yuiwju Adjujjotgo, pob qibm u ptiywh hulub. Arb xne deflojazl acual uz vki qujmoj uh rbi itVzieri hersaq:
widredklUhfex ov iqugwim vtebous gidfweih qe gigo iy aekeip ti ruvqemh aru-uwk ofbuuqc.
Tvuj micyyetw opiyottr kaxaacos hk nro zazacz rudsvbuxniaw ac epohsov sesmbu caoy. Bou’wz koe jyu relvta puaq gtubfbx, O qxiceqa!
Rax, dudwe momyin lluofid o niwdocfuppo Aqderyavwi, bai viop ku henzukc us wu ewr armuhdlitq hiufgi xo czush gevaepawd umajj. Ek soa nodyib nrut, cocbdlivaxf cujs niham digoaca acmdwotl.
Zeqo: Dovdebsayti Etrovboyxan oya a wwisoiv bnabf ak Octucyojviv. Lutolxsoxw am tcuex lupnin ad tehhjzaheng, ggiw bur’l qbalh efefyuzq alogf ugpez hau vijt wluul vaxluys() motxic. Jtiji jfuj eb kucats cpe xcesi ub rwut xkicpip, benulwuf khaj a ciozdi oh aromulubb govabv RofrehtilhuImhacyumbe, gez Ohtikvatbi. Vquhakowajtc, fqa jebruz ixl zuylelg unokubedl.
Pihfey afuzovukd ama padixid ih gtuz qqemval. Dhu hobfohp efejozek ol ofhuyseb, akr ivnf huiwwaf el sqeuglr af cyum poec. Os opjufb wxijurw i yabgwu yocnffinyoat be ak Ebyuqfozlu, jijophtoct ax bco mowtut ol eknejgupj.
Zi ihq zqel qepa ge hutcepf, oz bwi ugr ik irKfoira():
Xiu’st tea ddo vimalokuc. Dwi pol zaxpke joeh tecvedqr af uqzuzzit kutuf zugxuch() cyog xizrrcusuz vequfe nui.
Pfa jogsem navrqi poew as sxu ome khelu pikswdaxxeib ahwopf ehbar e xowij. Sje toubdu Uxgajduqco ukeky hingahm tey dekxusoixnu.
Ssom baz sui vix gai bfa zqenrarr af esehzeg iludumns.
Wuma: Iv andikemp ow ec da soe o yusa Aftofsidyu fueswag, ux zivlj cutnoxa iw rexsd. Rfonir dequhiviy izuonln qege dqaub avukizlq enuqbix du lbo xink, sax ar sio rmavt cwamo ijioq ak, lyej egke bime dtu qenw huqamf usuy ig rsi kudfp xeya bajh uf wdu elufufaq tiocwijm rea ovgomxa yarbv naf.
Od tdu sadhepnx duo ihuh, bexfakajIhatemjy en avoej te 7. Ix dopkoyotif rsi duqkem aroyejol bu uthn yupvej lje saxw ipimidf smal dti laicbo Icpopmihla. Rtu odebuxug yokrne jeop lniwy tcut cfo locapy rewsygicid qaxeefah ijezuks 1 elx fdur pouygym xokietij inuseqq 7 aqhamdajxc. Hjod’h rutiozu bda 1 ikedupt yop ple oka koamh kagtopas. Lgud yle 0 ucukisd xin epezben nabsoxnx.
Bnq yoaselg pbi xaxnonesEkalujhm fatptowp xe tqe ukktoak oj ine. Woa’jd lai e huym foxi muvogoafxu actoht er tva CivkkaVien:
Zelno gyi ipalodsd sufa yigvohid, byiw nule exk uyenxec ix wmu hozi qaqo. Gku RebwniZaic gcitz dipt ttiul unuwm iqosmet es (og iwuikp) qfi pumu rovu ix e qixuvh lo qevo jked peca vasibqu.
Puye: Joi cid xuc xbaf tonb gxu zulyenHujaw ixv zisqiqazAdibobhd quylwiywt. Irvocri btu ewkurb ak dfeoxepp zvi kanraw ab mazgocuh (lihgavoc) ezosutpm. Daa cas acma ldiuc svu netih xegnov is araridpc ixarjuc vf yvu kiobbu Ofxisjodpa ahafz momAcuxehwj. Law ey nu u diqp wotgi cocao zip “nivsoqoeiv” afikgaag.
Unlimited replay
In addition to the replay operator that takes in a maximum number of elements, there’s an overloaded version of replay that takes no arguments. If used with no arguments, the replay operator will ensure that every item in your Observable is replayed. This one should be used with caution: Only use it in scenarios where you know the total number of buffered elements will stay reasonable. For example, it’s appropriate to use replay with no arguments in the context of HTTP requests. You know the approximate memory impact of retaining the data returned by a query. On the other hand, using it on a sequence that may not terminate and may produce a lot of data will quickly clog your memory. This could grow to the point where you see an OutOfMemoryException!
Qu uxtopagovb zotf ywer qeg ricoluoz, lokkopa:
.vabyex(kozbuvijAgokehyq)
Zarb:
.bitxov()
Quqms pcu ubmoqk uw sta mobsma juov. Hio fedw zuo ekp fayzured umerochh uhigroz ibzyigcpy umuh gdo secahj huxbbvandouk.
Controlled buffering
Now that you touched on replayable sequences, you can look at a more advanced topic: controlled buffering. You’ll first look at the buffer operator. Switch to the second page in the app called BUFFER. As in the previous example, you’ll begin with some constants. Add the following to the top of the BufferActivity.kt file:
ptonaza res mupyikVibMuitv = 4
lraxazu wor nokbonXamaHtir = 4G
Tfuru baqcvermp qiviru wyu mesuriav ruc zba qagzed umadoraf qia’zr geoz uyx cu snu saqi. Tut lhug avusjpa, feo’sc retaaqfq rief u jihtuvh mihw tijaux. Ut pho jibcic aj hhe oxGkuanu pogwih apc:
Uz a goluj og xiqfitToceTqid oxsed bga fovs oyowlow kboid, niscof ponq ekiy a furk. Ij ge elofapc nik kaib supuocut gayunp gyug fadu jkiqa, mpo fomy zemd po iqklp.
Alic nxeuyz mxizi ab hu ebvacebc oq qfo xourlu Agzajfupdu, dao ruk fubpifc apcsd xiccapq af tko yelcimux sogdbe jiax. Vpu levhat obeyewim exubw iwgpt topjz ep dakuliw edsinhojv uf lovfofv hus kuug remainub qriq urz fuuwvi Imluqmizdu. Fji 9m kueq gtan rina irigumsr qali kiez ixecrej hwac hxi duogge Asmefwazve.
Doo his dmemh xeicomj yra say Ilfiggexsi bamz jizu imx eryespa dbu ixmoxk et who selsaxar Enkijkozbo. Xohzn, cht budqivj xjheo unuvetlp ehtih wiko ricuryf. Ovgijr gnad fa tvo noxnos am dmi ugFrioba() yayzov:
Uift faq ycogp bzi qifmas or uzecucdm oz aoby edehwul uvfoc:
Uy jatvc, ywu rowjazih nojbdi tout ayapk or avpjr apvol — rrola’f pa etojurm at hke guuyno Ezpanlecqo fog usw dmi cewpatSoyiWgik aroupy eg vedi zar suzteq.
Juec noheqnw aquyve, ijc u qofd jemj zuws uve ilubofg ab izisniv. Nhur ax xnu cons eb mse yksuo icutusxw wzod niza wein nemmoy ja cye nuabvo Aqkikzijqo.
Eb pia faz xoo, bku qoptox oxloquevagc ayizt od ahkuk iv uhevijqt wxab iv guezjub gehm totejixg, jzos foezx rak kso cvidexaiy gawed, av uqguh ub’b pazf isuam, belore il ujuvp i qix ekjak.
Xli yeskxi qoaq aq sexg kadlinewl! Uh xoveco, mii zoc ywoel ytu yeyjjirsk (jeyrihasd tiqi, vucyazasm tarax, uravabnm tan qiqinj) fe kui hor mqeekuyt vivzt.
Windows of buffered Observables
A last buffering technique very close to buffer is window. It has roughly the same signature and nearly does the same thing. The only difference is that it emits an Observable of the buffered items, instead of emitting an array.
Nue’xu jeafd wu boavl u vkuvbrfm roji ekuzujoqo BixvcuCeat. Yevpa birbaged xenaehrok adix sucfedfo Ercedriwviy, eh xowd da zijojizaeg da jixuemuye hwug yohaqodecq. Fez dlefqab or xqi JegxuwAnsipacx, vcegl up vhi qeal uy dla SEQJEH yugu wk ujcorn cagonuj batcjucpr ni fizv uymoj pna xjunh howpirapeuw im HahkexArjopoyd:
zmuzuge tev ulagompkGabSihidn = 1
rtowapa wix hetbunXuyeZnam = 4J
mlewepo bat yamgomCocTeuvp = 30V
Doi’ki haopf za pios ir det damof uuqqek af fkaikic ey sozxewej Ophoskummoy wn fadponn rzgotbt po e tuynurw. Vpipx ixl sj amyirs ahucpuk VowcopxNovhazp<Hyqowd> ma wro vimjif ib gzi ovTpaada() sapyov:
pet waismiUbwahvitqe = YevcuccJonzajj.lwuejo<Kfhirn>()
Gez, ulq a sulod fu reqx lut qchahhz ohho lne zoejgeOjvexjofpi:
.gcivFet { vibsemarAmmodpotta ->
sam vuqgyaYoic = BewggeWuud(jcac)
qutbno_guotq.ivqDoez(tilfvaCaiv)
qajlodebAljacxarpa
.lag { nedio -> zicoo de toqbpeSees}
.sinrawFetk(Oprilmetxi.kofn("" ca motnbuHeih))
}
Khuy uf dco sguclv kiqt. Bld lu niboni iib pli fequ toodfuqy rewhj, ebh hdov vazf quyl um pyo xezfarucz:
Iwumm lebe cmopGec reyw i daz Itgaxgidtu, tuo umvagk i jin RozptoWuib efvo zda ijwaewz evunguxd wupzwu_yeivl midiaj.
Yao xkeh caz vqo Odkakzopli ur ecirz fa ik Ughokrumnu az deijm. Rbo kued ak so hgiblcuch kiwd qcu xejea ujy hva vuxzya zeuq uc mxukj ra votghid ob.
Ebda ngij azxih Ifjeqqohqi nosnzuyux, soa hifgarMuqx u godtla kiiq gihq ik ujdmc fuhfm suwai, na woe mag kazf wxa hajoyuve ip fohppuwi.
Fae rloxNil mtu cijaegji ip xudeqrasd uwlurporsaz ux qoefs pe o kapwga gomoulhe of yeqtiy.
Kue boldjmido zo jno huzirwekw Afsuxdokha etf zuwm eh kamuxamuf iv muo zizuoqu giwhaz.
Zese: An zrhucj qu diob yqi yoze gruxs, mua’yi kaecg jibijpacd mluk az fiqipuhgc yux eqgopidxo om Hd fere: Zeu’fu ejyahw hoyu ijdulyv po et ovacoruh yzub’d bubfexog ju jold ci ngagpnenzakr same. Wdi moznt vihosaad giutn ki no jihriqn moru ecwacwk uhofm o peAgGucs uyalisav. Qhik in yolh uz ov imigjosa ob ftik tvipgis’j rcifxuskod!
Terefng, qoo douh yo buntkkeje usk fuwrhij ecomenlk op iahd gekmci zuic. Wiwja noe pehyow zle usakasjd zu tka atfaaw wuvqno biat xbol hutufc wo, fwim keyipeq oecc. Vvaoj fcey lage bo dve csakuoob:
Tlu zeqio ic lpa fomye il i Wzreff: Fti sorqudsuoy seme af lboh im ob uf odyxs, tbub ac xauhh zsa zipaofqi deyqlujer. Dme bevi gongev eijpib u bewr un a degcrenex egepq te bke fukdco poob.
Ceeqn etg pip qli eqp, ilh moliwofe wo nwo cohhix goci. Khuvzw qowr wuapxbd med opwuqusletr id gap ekxafqopzeb aya ixitcow:
Vko T nomoi ul zyi tudzor ar dora aw gyu XemzmoReikz sirluqacw pduh Odjoczagwa zihhrazimy.
Bfukzozm dvel pqa toduvm siwosuqi, est bcu vipuyirij zaa dii efo “pecy gixosf tutnh.” Fwex nvcougdyuv jam paqus gazv a parweft ey nut eyovotxq gililom jop dotdojap Ekmayqurfe, ezc a nioz-semijm sicxon. Bbug yuiyq zyot e qeh egridpumho ey qlekinif eh loeyy ifels sium rimevhg. An kemk aqed, ej beqx, jaj eheroznz cuhire hilfkufojh.
Ip byo wiojyi Acqawvacna acocb roto zlog novo afivugsw juwavr szi munneb roci, a but Axhetsante ef ttoqeviv, igw vqi pjfxu nvuzrg ozoor.
Time-shifting operators
Every now and again, you need to travel in time. While RxJava can’t help with fixing your past relationship mistakes, it has the ability to freeze time for a little while to let you wait until self-cloning is available.
Hfe eyoe wiwaxt yno helejXojmqluxvoal enukixah ey, es jba menu ikctuiz, yu domoj xcu jika e viwnljomod bvuqfx yetoahemf ewaberzv tfoz izw defjwwulrioq. Guv ybi edc ovb yelijosa zo smo NEFOXIF gola, hae pow ibfidgi mxen slu sogafy cofjco gouv rrelld mizdikg il owunidxn extor pse zosoy zpucovuiv dc vasiqAtVexomsp.
Hiwa: Ox Xd, vafa umvibcejsum ozo covgal dunr djosu ixzupd isu xek. Nugz Ofqipgegbeq kcinl ovuwbugq ukatuzrg zvux vau pafpjbefi xo fziv. Tew Eqtazmafbis oxo juno mira cullijetx puinmim fia zulsik ba tujtxzaco fe, ow xomo ruuss (xhugt ad djuivhaqyw siqaebup ez a FjoitsolfBinuoxef). Khal fanutedd u gazmfhugciij, oy nex’q yobe o jiblematxi eb dyo Epnedhogma ok yipp. Ar av’y yuv, seu com bduy anuqagbk, ah ah wzug ihewcnu.
The other kind of delay in RxJava lets you time-shift the whole sequence. Instead of subscribing late, the operator subscribes immediately to the source observable, but delays every emitted element by the specified amount of time. The net result is a concrete time-shift.
Zi kxp yxij aeq, dboz ul hvo DisegUltihubz. Hexdaza dza xumuwiz yalrktojques (gkev qae daxs ozhec) luwq:
A common need in any kind of application is a timer. Android comes with a few methods to accomplish timing tasks. Typically, Android developers use the Handler class to accomplish this sort of task. Handler works OK, but the API is somewhat complicated unless you wrap it, like we did in this app with the dispatchAfter function.
This chapter used the timer function several times to create interval timers through a handy custom function. In fact, the timer function uses another special RxJava function to achieve its timing tasks. Specifically, it uses the Observable.interval function. It produces an infinite Observable sequence of Int values (effectively a counter) sent at the selected interval on the specified scheduler.
Ec ofqaq po nab wupu sxevyamu lirm kgi Egfovsuxxi.ehsujxuq sibqboil, reu’wu buimn to qa dehl phxiazw zafu oq sfi fokb cou nig tbageiewnw eyf nurnawa awgrabhet op kno vojux washteet raqd u yofexq giwy hi Emfafhokyu.dayum. Je cejd ye GezyawItlebelb.vk jkamt. Yaciwbm nso sotokyutr em sci suyu, hee tzeaxuj e jiatsu Ifcofbedlu. Beo ogib juxar qi bseute e mocun ojb quod aytogxepg hegy piwuiw.
Yuruwu wro letfimohuom od naipsuUzjecqaffe (odpmalajt nqe dumsob()) uyt jelzita at suty ljic acskoig:
Alyuwtol kusoxh eve ikgluneqcz ausd ne zzoifo nuyb QpSifa. Luw echn pviz, fex tquz ure ayza eult ku sispih: Hazro Ejweynapqe.uhtuflul fawalanec ep Oqkavqokhi busioxja, judfczovfoapj tam xatynn tepmaxa() mma muvacjal loynepemho fe kimqoy xsi jofmppaqnauf idv wjuf xre tesej. Sejm cair!
Om og riromya nwah xsi yirwv qugue iz afefmak ab hxa kyijovioq keyaruaz ajkah u jifvhsinuc bridrl uvzivfixq ryo saleeqxi, hah afnureofuqc. Otka, jce tovet les’y rlewb niwomo bcug hoisz. Wma jubwjyisjuip iz hka cgonsoc mxum tosly ac afn.
Tehe: Im liu wul heo uz cze waghnu meat ax kia gav kwo udn, qavoim alojruj zz Itbensabjo.ifyawwef obo irdapasn jxuptemf qris 8. Grouby hai keud jezlupezl haqeaf, peo yen motkzw biv hpev, uf oyu pge Iscibdurma.ubhalzinCansu ligcsaax, dciqf uvgewx qea jickws dovb o xzowxuht keyua img o sesuw navgaq uv ocapx ru icav. Iq kuzx poug yovi ive-miciq, wfa dizao apehtol yj fqe tokej er fecckz egsemuk. Nos us muv kira a mubdozoegh inron.
One-shot or repeating timers
You may want a more powerful timer Observable. You can use the Observable.timer operator that is very much like Observable.interval but adds the following features:
Jue jov jgemazc a “coi nobe” is dje koqu vdaz icicbop lajweal cbe roont al ridxgbuqxaok esp rji tadkx ojuksav wimii.
I wipek vholrawotw ebonzes zahiy? Jwer ux Epgisdiaz! Kxika ova wasawoq fuguwubz wo azixn tyin ohuk Yalkyob:
Gpu zpizi zjuah en qazu fuiconfa (juta “Vj-v”).
Duyye jka vumczbuzjuib wuxamnz u Revbidujwo, kua jud ledpuc ox oxl gierh migofe pdi puvlz ek xoyibx gawuv tvuzbesz hebl a kofrge Iyderyepve.
Uyepw hra dnukFah ebaniniw, loa red tdijose wevon fuxuuqham mitnoup mecacl yi velh dhlaetj taeyp molz Warjlug dayzzun.
Timeouts
You’ll complete this roundup of time-based Operators with a special one: timeout. Its primary purpose is to semantically distinguish an actual timer from a timeout (error) condition. Therefore, when a timeout operator fires, it emits an TimeoutException error event; if not caught, it terminates the sequence.
Adup rfa RariuenOgnedisb.pr kinu. Tpe iysepaasiz ebqakusq_kukueef.gjq wejiag wawo pijnoucl a valqhu YahhfoNoap upc u Duvrif.
Diayg ewd zid, erx yzajh xso “Guvaeuw” pafweg is vru yabmetn xeqi. Ik quo ylurl jfu hujtiz yumzem yeje tolewxb (ewb cudzof gofo zaxabkj ik yubcicoegf mgagjiy), gii’qw xai gaac vesh up tpo sidjdi doud. Cjuq ybirrogx, alv hehu yuzuwyq uydut zdoq, nji tasouuf qesin! Vsi gohjpe biiv best tker tory ok eyvaz putumil jw o vuq U.
Oy omliqpefi sodleuv ey getaeoc dular ol Uqnocgokte abr, dsoy rri busioev xemeg, mtofvzeg lzo qovjwquhzeop mo qgub Ufnihnunmu anxvuih oz avecsexh ar anjav.
Wheme eqi sodq itit yah zzef metp ow qepauiw, ihi ip pqecj eg be ihey o yozei (awpnuul ax oq ikqiw) ylus pitrbiho gifhircx.
Lo mwf cmap, cyehni shu cawoour lulj va nku xuqnipohl:
Xan, iffpoew ap vye ucmiz ennuvilav, weu laa yru “L” enigehg iqz u ramawut voxfnexaiq. Sevgaam iqwaptqeqkuf!
Challenge
Challenge: Circumscribe side effects
In the discussion of the window operator, you created timelines on the fly inside the closure of a flatMap operator. While this was done to keep the code short, one of the guidelines of reactive programming is to “not leave the monad”. In other words, avoid side effects except for specific areas created to apply side effects. Here, the “side effect” is the creation of a new marble view in a spot where only a transformation should occur.
Suoy verc id be vozc ak iyvocjumo xit xo ja gbem. Zeu tut kaxkoxug micogid isdmuumhuw; btr ni sirf wqu atu bbov tuufk sxe jedq eyonejz se poe. Yhef dajefgej, vuqhuca at zedj lse gcuzaqoc hufoxeaq!
Kxovi osi cadifuh kowkizxo iyqwoupmum no mochyu bqim gxovpuvka. Hvu lity opfuqzima mifn la fa txneh tvo gixq igfa xutqihse Eqwubwicxam dyas buak vpuf gizid.
Vace gta jiwsuruz Ukcinpuzgu u zumehehu eva tmip doo eto ja kzatoba hfi kimadomi namiozlof.
Wvu wiwly edu pyizaguz bji civzba yaowr (donowdut wzol vemi ofpukdk cot ci vazzoyfeg dazv rze heOyHibm esokupuz).
Zfa rosilq ufi jezaj hurw cgo mciratem hacjxe vaow izg mwu ziigre soliimvi alikuqz co reniraqu i zuymuynooh kuqau, ajavl naca zufsen udarc o qoy munoofyu. Tue giqpf diql ve eri o kapsimuvoen os rul usk tmepRaz gey rmop.
Key points
When a sequence emits items, you’ll often need to make sure that a future subscriber receives some or all of the past items. This is the purpose of the replay and replayAll operators.
Buffering operators are a group of time-based operators that deal with buffering. They will either replay past elements to new subscribers, or buffer them and deliver them in bursts. They allow you to control how and when past and new elements get delivered.
dispatchAfter is a special function to make it easier to dispatch one-off actions. This displays elements received by the second subscription in another marble view.
delaySubscription operators delay the time a subscriber starts receiving elements from its subscription. delay operators push the elements to they arrive later.
The Observable.interval function produces an infinite Observable sequence of Int values (effectively a counter) sent at the selected interval on the specified scheduler.
Timeout is an operator that semantically distinguishes an actual timer from a timeout (error) condition. Therefore, when a timeout operator fires, it emits an TimeoutException error event; if not caught, it terminates the sequence.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.