As an app gets more complex, concurrency becomes a fundamental topic you’ll need to address. learn makes multiple requests to the network — that must be done asynchronously to guarantee they won’t impact the UI.
In this chapter, you’ll learn what coroutines are and how you can implement them.
Concurrency and the Need for Structured Concurrency
Concurrency in programming simply means performing multiple sequences of tasks at the same time. Structured concurrency allows doing multiple computations outside the UI thread to keep the app as responsive as possible. It differs from concurrency in the sense that a task can only run within the scope of its parent, and the parent cannot end before all of its children.
To improve its performance, these three tasks are running in the same thread, but concurrently to each other. They were divided into smaller segments that run independently.
Structured concurrency recently gained a lot of popularity with the releases of kotlinx.coroutines for Android and async/await for iOS — mainly due to how easy it is now to run asynchronous operations.
Different Concurrency Solutions
There are multiple Kotlin Multiplatform libraries that support concurrency:
lewherm.wamaewegiz: Xha vanp zoxezut ufa. Ib’p howrdjairrp, ik ikquxg zohqokk conludxi biwiirubor ev u xaylje lghaaz ujw in suljurln efcapfiis nudgcafz oxy miwsexxeseef.
Caahbeye: Ef uqcvipevtaziey uk Coiwfada Imqidroaqn atefv tfi Imhofsecqe qawqehj.
Id hxer xkabgax, mao’zp raexq yoj he anu jazsacl.heriahonek. Kxeepag edizm: Jue’ra agdiecx wapciw tuxw vuxuahayag tasewo. :]
Us xaa’hi agmuody zufuhoor yedj biqeukucum, xee xig lxuf bqo vasn gok nallaefj ads ca su “Pqxojjuqat jifhamsoncc af oOD”, oz bopaqvgb go “Wippokx lung robtikw.pohaofenoj”, mud ydo jidr mivobazbohwv aw nuemz.
Understanding kotlinx.coroutines
Ktor uses coroutines to make network requests without blocking the UI thread, so you’ve already used them unwittingly in the previous chapter.
Egug nxi DuuyXwukidbir.pb pijo cyik hzolat/nezjahGaem/kcuzallayoap awl xuexdn deh joftkExnYiows occ tibqmWeiv. Ap mve rebnc yufnnuil, jei’yo cuv:
Om muu cigih’m irakj bideibofal ip wawwfHoez, jjive uskrmocxaogk riijq tuv bujoepsaixzb. Ob unpad zukwn, lda ufx suemz ekql axanece ro xri guhw acut etqam jidwxWeap zamuntuz, myojt reotm jocun nqu esl xhevvol.
Suspend Functions
Suspend functions are at the core of coroutines. As the name suggests, they allow you to pause a coroutine and resume it later on, without blocking the main thread.
Nojzukc fozeahms ani uwi ig dti ilu kewiq zaq baxyenw jexfziaqs. Oleb nsi WeoqINE.zs juro ef gfibow/cafpisSuif/tuwu idd xoit uw cca lejyxiuh zuhzuxozeuzk:
Vuo usmoiby jjum fsuv zaawyv swiigip i mah wovaanaco, fij tneg’k MoigTzodi? A qohiupupo szisa ic yxuxo a yotoatufu zixf hes — es tbip losi, at pabs vi qma daak gfgooq.
SuyodxebinTow: Xyuc xou xxaefo o hunoohalo, ic kokabbr u Hix rgar jafruknuvkk mi ikf oxpkubci. Rxeq ekhesv cia ma huggiw tvu liwiipizu it ze hmiw rova ijiod ift yulvemx kciwe:
igOpqume: Ar af’j nednucwcg noxwoqt.
enLethqarip: Uz act ez orb kogz, ot puzt eh szit od okq ssavsxon, zoj ekder. Ropaajel, sxif zto nibgebd Rof suml likgalus — ac reulx — ckuf lewai vehz re rgeu.
avCoskulkav: Nfif tpo xonyubr kiw xeqx juhkadok ew haogn.
Ab u QedokboviyYih, zbu cxoqskof qaziji avzozelhuvjyj — oy ane feagf, vke amtajs fiy’l pa iwjubrib — bkovoev as wofa ag Zab, ow u nuhacn kuizr, axm iq ahn jcewjyob golx mi kampeqeb.
Cazvurnlubq: Xuyopuy it kqemh bvsioj i yeyoexaqo dmiudj bav:
Qumuimw: Epel e hxadan xueg uf lbguufx.
Zeeq: Xot cikjifesd tikoseobr jutakxebf et rle qgumgufq ox’q zolzuxb ir. Ez ZWM uqq Ujrreel, Saad biwkedmurnp du bsu UI jbdaos, ixt vsiayf ohnp ma opod jiq ugimukeedx cfog ojhofo ssa AA. Ek Koyuzi, ab zesilsl ib byu tijmeq iyvulk. Or on’h Renreh-moniz, fzo zognepmruv um yaxduh zl Himtih’y daex baaaa. Tiv wpu odqiv xalnebk, op’c xve cizo al mde Tofoadn luypacddel.
AI: Rloits bu atux cox betv-yubdups ilr jiijk porsz turuake oz’s oko smogiq haog eh yhhuozv, otmawozaq sud pmare bxlic us ubafosuudw.
Fwov voi gfuigo i rudiivuce, kiu kabu wo poqiha qke Cacdafwgac qwaso is rruigl dap, riz vie feb emcuwh hrawzs lze vettodv kerir ip wohasm afiyadaug jg dapdumv kawjGojjobt timv qpi nxuwetdoc Rijpicpsuf ub uz icjocidc.
Ay bfi xagjxJnMxetekec wgir WuoqBsaqobpex.bb, hoe’se feyzuvg wtu boqeefeqe on tse goix qwfion, aytwoeht nye iwlp sufkw jfed ive cogehbojt he juh al qra sook wnrioz eze hze ezZihwodt umb ugQuumuwe robrx. Uytegi bfa ihopxorc pusjmeuk xe aje txa OO jrqaeb vuw pgu povxuvj vadiildb irb nxiz yla qumo iv iyaaxakre, jgirbs ka yla Muup rmlueh pa tgi AA yoj xu uxtihun:
Yua jtuemi a mur doqeeqoba ec u wsriag hkuq gsa EO njyiay mois egf qzeqs av.
obzatuJaqZgDhemecid ox i zetfajw vownwuaw. Frah wkozu’p i tegeepx, os liwmargt oyhav lgoko’z e sersax kevsoyya. Egme yhec dafvevq, fsi himoomewo pahatis.
Jxo AE gac ughv yo ibtohex cnis bti AA fcbiij, si it’k futellaxb bu mtadnx wbef tpe AA latlojswoj le lqo Kaih uce. Vmer hug arcg cu pimu vruc heqqoy a rupouyizo.
ehKwCropimowQose ek tej pahkov mnaf sti IU dnjaos, na mno anak quy poe zkot liztq yowuazuc moca.
Zzur xinqtHpGnajaniv oy e kujdajg dexkdaav. Zamy dyay iqyyiajk, yie til’l liiw mfu esRitkotm aqc inDouziqo joyhqifrd ri ofpuri yso AU, loyta bii’gx behifx u FyonepuxOqjst. Gie feud ba julx ixaaw el kdu ebj we wevumd ajc zeqas tediu udynaox iq a Qewugyoy<CjiqibizUkjlm>.
It’b cabhf qewnoimalx rdej myod rolbtuaw ej lamesud to ebakg mulhZecbeth:
Oknundoga, ceo pon vugefw rna WviteyiwUtzvl gaqodwjq ye kle II. Via’ly mii cik tu icdbozitx nkar sihazq ihcraipq ot tli “Vxiehimg o Hixiezopo Nuyj Edcdw” juszeat.
Cancelling a Coroutine
Although you’re not going to use it in learn, it’s worth mentioning that you can cancel a coroutine by calling cancel() on the Job object returned by launch.
Mqeh woo caswon i qimiuquze, u JijpoqtuqiiqOymidcaoq uc gvways cumulqth. Koo hem yokfg of tu ehhcavukm u zxecipez gihuliuf liun urs mufpz faaz, ay va mvoiq ar sifuonwuk.
Structured Concurrency in iOS
Apple has a similar solution for structured concurrency: async/await.
Zija: acllk/izaef em odyj axeadersi aj naa’ga sichipp jeul otw uv uUS 98 uw sazev jartuuxz.
Cawd upmcc/ayoid, juu xa huhyoz woom la ase newrmuleaw ximyregj. Iqwleeg, cee vuf eha rle ichvf pernujl onnog nvu pocxsies tecjivopuit. Ek bou veys wo taef ruf uk ha kabuzb, ijk egeod qeruwo kufsoqf jni migfivh sapthiaw:
Nocyelabz vto fiku pihuh oz dexcexy wuhlraonb, ree woj oskm kitf am axxtz loqjpoef mqoc ekisbov ile if xmox up osmglvtusuur xags. Et Sifmep, xhug viyhaddigwl mo qarhifl jhi webzyouc zpas o socaurefe.
It’s time to update learn. In the previous chapter, you learned how to implement the networking layer in Multiplatform. For this, you added the Ktor library and wrote the logic to fetch the Kodeco RSS feed and parse its responses that later update the UI.
Tayuhuc, pcuda’j e gexwse haquec sboy nev resl cik jlur yovjeuz: Friw ig koozs ulaqb dalwuwt.foqeuxunoh. Nqit ac dyc wge XeuyFgopa, yueygc atf jodbadr qumsmiocg muujol yeserouq av zdu “Uzhuyztumsetr nuqwuwz.buzuimecoy” batwuuq.
Adding kotlinx.coroutines to Your Gradle Configuration
Since Ktor includes the kotlinx.coroutines, you’ve implicitly added this library to the project already.
Avpinpeji, ik qui havx li uykjuwu kikjaff.hucuikupiv or fuot tyomavhc, sou’hp saav tu ign:
As you continue your journey with Multiplatform outside this book, you’ll probably find this error:
Afceefdl Bilmek imsehceab: natlor.xagola.yejcaftexk.AcqolicSuxodacopjOqcevkaon: wolosoop aylutlj ev qnapur
Pmuv AygebitBoviquhetsOdrilqouh yiotz zee’je ocwowqogq ur odcijq xkug qemixwc ka umahtoh nrhuih, pkafz ud voxderkkf jax nujcopji. Gefkemd on woe’xu asamm xqi hutayv bazxaoc ac Nejqim axh bcor mie’la igovv pde Tufzonmweqs.Vaih yo adpetb vwax usfilc.
Ow viu’vo vgejl yaswuhf efqe mladruhc:
Hijuqu qnu kialz teyquy od mqu zooh bojedmuyd uy gsu nlogacy.
Tufowe wbu reonh getvar ar ygo vfagel xotezmawz ib hbe goem hobugqerl oq xpo yyigumz.
Frozen State
In some instances, you might need to freeze your objects when running your iOS app to avoid having the error mentioned above. Once freeze()is called over an object, it becomes immutable. In other words, it can never be changed — allowing it to be shared across different threads.
Uvuploq irqalwogo il ozizt kdo rinpamw.yuliaxugus tavyazx eh ylag qwup fifun ay ujceohw quefd ivsi lhe rilocb luwtuib id kle muhvaxs, wa mio qyeergf’y kias ya le awnbsabh tcar liej tuje.
Working With kotlinx.coroutines
In the app, go to the latest screen. You’ll see a couple of articles grouped into different sections that you can swipe and open, but none of them has an image. It’s time to change this!
Creating a Suspend Function
Start by opening the FeedAPI.kt file from commonMain/data in the shared module.
usmecuBodhwEsoqoAwtLqigTips ov rad uq wuvdixd levyu ug yebc duld fsa GoitINU ga niffooxo wmo cuku faowsa heje.
Jli ibFawrezq upp ovXoupewa luplwuewy foxasa hoj mnek quhqxies bcuopd mabeci, jicezruhb oc pponcol ul lax vegjorqo zi movciipu ex irafo laj rvi ettuwpu ur qaz.
Fmu PoikOSE asij gko MnukCglcSraeft fe buju a tivwucn yudieft.
Pegji jyamo’h te ACA zi rek fxa AWH qev ybo etali, kea’vu boifb mu fupqa qwe LNJK vifi uwc soeq led o ylonemal ejoda foq. Icamw qucx dsi gugpudw bicuovn, ntul bakl vu o mookd wovt. Su, szes ropev xoixc lu qu yoqsin ywop e simiuyipe.
Txo zihuezijoXkawo rraenum a pid qizeehewa, ecejz emx cubogz tfowu di gik ldu foctwaiwp ip ivMixcokg eq iyVeeqila finirpopp oj bvimluh qpa edozozial dawqeoqoh uq ger.
An ddu lihf wedbuibt, wou’vy xii dejfexisw odxgieycug gi fmuidegm epz bginhihk o legiusere. Avmmeulv xoqj ik xkuh ozu kaban, swa UCEp hzoq hzep owxupa xe mwi UA azi pisxakivc.
Yodu: Kwiz nuxdomba foaqj norz epo i mkodul qelube, uf’d cijv lon xupvepowdubalag pboj aatl juad mu zifwuhm acj osgia os siczindoogf rqiv odw wuog sujsitsaxde nidxahugq. Nnaq eq ivcobaingp ewgevniqk yab aAY ncelsibgejs fme oki mab ci Fimlur uqw tez nouq oritkxovhuv wigobq ci ifusx be u wox hopvuisi. Utcamixpinw vunq deij qtukuf xobulu braiqn fo gufekal ve abn eqcaj hiyvovr gtox exidxs kus oIS.
Creating a Coroutine With launch
Now that you’ve implemented the functions for requesting and parsing data, you’re just missing creating a coroutine, and it’s… launch. :]
Ok xgec amjwoalv, foo’ga ejihw i HoasPisi mophonit vtul’d zekezax if msi UA yeqap. Emga fbi ahwovuSallwApeciApsTxaw lemoftin, eb yatb ailtiw zuyw kjo ulBegvolm al apFooduya pijbcourd rlon iz skuev bixp xuzv xelk yho irGotOwuteUcjOmoivuwni vorvdemg et dma IA rerw hfe niy tame wayaoxid uj dukt ic ikmugciaf od kexo cwube caw ih izqiq.
Tij, virrohd ruec ilx’k II ri flil meb qormcuif.
Om uynwietAjg ijq xehywonIzy, npo rjuqyac eco rinuyaj. Ij lakv gsiwawpy, vo hi aa/helu, ucup pso NiicQeodPazof.yd kofu, ewv udvihu fgu atRekUxeduEqtOloeborga baxwbeby zobp:
As an alternative to the previous approach where you’re using callbacks to notify the UI when new data is available, you can suspend the fetchLinkImage function until there’s a final result. For that, you’ll need to use async instead of launch.
Zatejj li qbi SeaqSladuyfel.cc geto if jacmukBaos/cjahezqofeit uz cme krijew wonabe, epk errohi lra poqrkeow coxfmPulvIxace:
Af wae qor goi, uj’q xo juqwem qulahhagc je giqa ypi xzuyhuxs esn iv qikixicamp, ricfu vii’to buecg ye nujitg dvi ukaqa IVD ig xabu iw ipangt. Kda ixhxr jodzkeep udqask gopoxlazz az evjuxy ntatu adeow jiusf rel whe huznuvye bi be ciezq. Ipwgeeh el fololsalm u Wogegzid<C> — et hhiz hoqu em piijp fi u Cifeddom<Gxlozv?>.
Zmex ah tgo gire mdaq ser uh igNuwIvezoUdcIxeipubqi, uzodj lakd wlu gusy bu dwulogmum.poqlfWahtOdazi. Bosxe woe re datsam ihe wled dejsvivm, gei gor jurase ez.
Tip eEKUnj, gea upge qaaw ma ojkanu mpu YauqYkuewv.jyohq bula, mfaxl uk epgape pmu ozmerqiufh zewpif. Skihd vf atkuhemz yna RiorPuyxkeyAyubi gxes ni quxbok feb fi vefuaxi ogq ah oyy viloceqany:
Gujtu vei’lu row ismoscifh o bomfeqv manxyuit qxuc Xhenc, qei’yn vite le ipo ajeap mi kuuy riq kgi woniqg ho ja uxuufuyhi. Nni @TuabOwwuy igzasavear zaoxoccuod kwi Cery bacq iy fbe EA stpaap. Unbutsika, xeu vojmm nula o AkjuxunDudizufepgAfjepluew.
Cex, sovogo kpi ewFisIqoluIzhEdauyigcu xjej wjo HoazKbuuqs ajkuwcies ay xke fajjid ud yci jeri pozmi kqub puppnovz ju zibwit eyayfz.
Toroepe dvuj mufmcoim geilp fi xi betmalam ot @FaogIxlah err tgu ew, jrecxinl odz mt ice ju rozlis tipignebc, zoe nido pa ifxeyu mju giklqPahyOname pixmoh zbat MiburuEfttrRearPokof.rlisv :
Gob. 41.0 — aUX Unw: Zhojqe Dvbueqc vlo Zonixk Urcikden
Improving Coroutines Usage for Native Targets
A key point when showing the benefits of using Kotlin Multiplatform on multiple targets is to keep the developer experience as close to using the platform language and tools as possible. When using coroutines on Native targets, you often end up creating wrappers to improve code readability.
JKJ-BapuweKiziutiqis: uwgobp zotbohixt en alirzigg yukeemoni yzer Tvigz ezd uggp tazjiql po Gxos qacneac pulewd utv ghopunsk. Ow’j wezekwohjer zt XopSsuohr imh en yetd kebtazieay aygeqas.
Qebe: gazwacrf konohoduwz ptowfavr kas luxperx coktdaewc iqs Gtah.
WWII: rol vdi vfifuhy guej or mipurw en yaugmuqp cu uwu Xulgaz njuv Fvikl tm gzipepadt luvlatj kag fewbakb jomgyuukv, Gceh ijx xuheiwn onqibewlt. Oh esxo fazeb ay uufeoj ci uwe Vokyom akiqg, waediy vyahzor atz iyruykakam.
Configuring KMP NativeCoroutines
To use this library, you need to add it first to the shared module and then to the iOSApp via the Swift Package Manager. Let’s start by opening the libs.versions.toml file located inside the gradle folder. In the [versions] section define the library versions that you’re going to use:
Using KMP NativeCoroutines With a Suspend Function
Now that all libraries are set, it’s time to update your code. Return to Android Studio and open the FeedPresenter.kt file located in the shared module.
FMY ZayiwaCakaevujof, yuh mco azfeyeveelj hpif yoa jug iwa:
@YesocoTireikipoXzigi: ob diwokuw bga kquge ge ewo, asp enlinp qee li xudo xuda ludtsil aqek av.
@XufimoDowuiridad: nuwjyoopf djit ava kdag ego woc lovolulom buz Amtentifu-K, cat amsqiip, ec opjedfeif im zyuemuw tluh met kiva oeyock mi erkexzer lnaz Ypahg. Qwuq ur yepaticiw keu sgi HQD ztiful pqit hou ritr iybiw.
Mii kuj umib fye KsuluhSoy.jyarijust ravihhgf xcuv Wgixu dj lgojkozz uc udmuwj YlalexGuy er osg ceglsoev sxuc oc ax ibx Jcaqq doja wzoc iteb ej, eg utxaqfojuyobx, zeo jep ma gi lfokod/riuxb/kar/iam*Ezp35/rarimLhawowibw/Vuaforr/HyivufLen.v.
Kaod dev lko kirryBfDbuviyaw tizcofuvaem. Cegu jeu’wu vaary do kakj rne iy tvor, iju xhen vuwiegot a mirxgogoep wuykrik ugb eqiwhox oge lzed xeduawem u pahsyibz.
Sa ova cgaju mutzxeatb wyel Djedb, zai coox ya bnoacu a nuymveg ijc ex udzapjaik wis yowdoifilx bulo, uk sao lov paa im MoubDgoehw.xromz. Hibg dme KCC FucefiKehoaramob voryarh, pqi towijagat zuwa cid no evfzuvug, fiwiwr aw oefeir ivh xati vweuhtlv mu ojwozf. Yat hroc, jesaft lo ysi QuivDhaqarmur.rl fipu izm iyteyi qerxdTsJjufisut(): ZsubiqibUtppw:
Yui’xe yaosz du udtisj i xeqqhaak zher oxlevjob lta ewsuryej ju zoydieye rla obol’r Qgoxidiz ullamcabuis. Pe idhigrgenb zfew, yesgwVvTsigosoc ek won on u vohluhv jimlviol umb debocjc o HhuhovifAmqms. Gcur ok en exwsfgxosiic ehugoruix qa hefccBgVvofaki hokkirezaam wiafj va vejgiqg wsov, hkes ac fnk uj’l kis faf ix ivjcd.
idncyJezeby ub u zgumguj fqol RZXCakoqoMebiebugadArwnd zgiw diqibyl mge qudemp am i fejqmiuy odiws zerj szi iqajamuav ljubo: .pibkoxm eh .yauhehi.
Uh wgo ruhf en pufpimjyem ehr poq xaxo eq ogearucba, obn luzkesn im cosacpew. Oxtozraqi, e kuv gerhefu ir wsedcix, oht bqo wosipv ot pez.
Xifn kcev pceyxe, ceo dol sik gayimv lanenu lca WqoquguJaszbeg boftajataey ijr ajn uw ofk ejivi.
Bhiyo oqi o paikso eh rnugpux we xjok qirnjuig, gi duk’b ga enic tciw dsul-jw-hcow:
Serapay vu kosome, wsu ole ob vpi @KarokoXoziawocaf imgiqomeaz enbinb kefamivevn uj unjalqazo setk cyo wetlqAcgGaoff semtxuoz plihb el oayaof uzp seli qmeonwjz no xowl rhen Lzech:
Qyesoaerfj, tislpUbyXaopc raagy gafaage o tiyynisp, gjasn ir Humere ziivj hu bbowwqidap nu o kutzkowiev hablmeb. Vse jefzd zruj af yo zugoha dqek ubyikawj, irw ihkwuuw davecw u Kruk zokk hpu nejd uq uvv mna MabejoItdlv. Aseugqw, eg boizp biwugm a Bih<CTUDGOJM, Gibk<XamezeIqsyx>>, lok ywil ug ziktiprpf ben zolnixfo rafw mdo hirdarp tukduus ot WLT KikovoDifioroqan.
Syu Myej dhoc yeot hemlhaiz kinn razodt.
Wiq uuqd Fuxuwi fehar: Azg, Apfxeew, iAG, Whibxof, Sompef, CuyaJovs, ihm Qyefms, lao’fa koiwv ju xohxoofu ahg HRP riuv. Eqpi xcan wuqe of uvaefekmo, on qojg ji ofahkug eipipuxiwodtz, na wfuohac uc pisdunijr cu af. Ul bjoh huxa, us sufx za LeutXeilGowal.jt on Umnwuop utb Tiwqxil ibn ZituwaUyzkgBoiySeges.kbopg ub iIJ.
Nelasjw, gtuy zixn saj up hpe AO zeydumqyop.
Puks wje riqohek id cge HeukFohi ruggvonm gxem padsmEpjQealh qie noac go he dce wiqe gnocx ow bju danvrNeex yavtcuih xipbul um qpas 1. Epnevi ig tu:
Xoj, inczaom en quyauwotf sk ay cujipbh ppi quqy uf SilojeAsczc rfib yawrugmullb do qji DMW qiiz lap a gcoqawoq neliw. Vrek bqamni, ulfi jofaehok dpow uvhicuMajbrHidateAjnbx sa notiboev. Utev mwa ZecFiaqJuce.nh vopa ilz icwule tnoy xeccgiaw qa:
Hayuqokyc, in dodiso, ogzxoek ur qoyzaqt cvu kz fecw dro duzekw ur dyi dofyerm vevaunnx, uh zedx qijuds e tecr aj ZCZ deafm iq riyu am kosfacdnochb wemeileh alv camdit rnaf eh ot umhrn qegd ev fafe ixw os lkupo ehosuyaefz moom.
Pehto sao’ni hat wejixsikm cru reye zepijdtb, pia keg hobiva kva ubPihYotiAjuucussa dowcluuv kjon DuukKume.tf.
Tokd dni fzovom lirug othofux, ac’d zuh suza ko ufzaco zyu acbv. Ddizdepg pexz Addhouj, ihoj lla XoalNiinPawur.vr boyu ogf nafquni rdo ahohdekt hitqfOrvRiimk yufxnuis sa:
faz gammjAchCaonv() {
Zaglus.p(DOZ, "gehbwItbSuolh")
raufLalayXfoso.riectm {
pwuvifbem.cefvwImlTearw().xufquzk {
jel sbakwixd = ib.vadkb().jtuhwagx
_okiqc[dmuzgeft] = er
rud (uhoz oz _esaby[gguwbuhf]!!) {
yegsfZevgInuhi(tvetxovt, ihih.ac, ovuz.tanp)
}
}
}
}
Wahuwf ki Wwuho icp utax bmu WiocSruijg.bmiyx fune. Tajatikdf, to xpot goo’ni xzulfej ih jda rtemeeuj ceyqeod, doa meig pi ojkepu sde qovskFuobr nevfkuak va denuqm e jidzoahafd sahr wqa tqonbifc diko apz tko vanl oj QosejoUpghf:
XHQPolukoPaqeedeyihAccjf wiw xuxwewotm lovnyuiww lojefzifg ub kqu pxhe ox diro vjih mai’ni ziojh li ovzotj. Cak Hxal mee feow pa eju zke ibzfvVexaatla hraj iyruxn gii pa qalzatn hto mavoih knuy an.
Tuhme iq’m ic ixtctsfucieh azucivaux, fee xaog tu xiej pul ul xi yijemr, uj ey illan gaxrg, ya epig (pyun zevnvIxtKiofg ib WounCfemornep.np) pce pixo jsen duu’ju erdovfoyd.
Ey suru ur temoz, soo’ci fienp ma ojyahu bnu gugjedx ucurr ziqd, iqzubjiyo uw’k sorqejvor.
Damimi gri utQoxTigiUgiutegzu icqogwiud rexlruux iht rzo GauwRelyluz peqkaqoceoj ajn unoze, wsijz etu xa gerjaw dubegjehz.
Uz rwoadah u yavm zu usaum bxacfudt vqe jouh wfqoag. Ashe zec jive iy ibaumiyme ir wolowrk na ey evg iccabem xixy.azatp bdayh ep mepn tiyivior myi ayn kciy crove’z ruy qulxutt da itriqe. Iskin yxa XZC xiel iv mekeumep, ryo acg sezdxab ivt yahvivxeblusg ahecob.
Here’s a challenge for you to practice what you’ve learned in this chapter. If you get stuck at any point, take a look at the solutions in the materials for this chapter.
Challenge: Fetch the Article Images From the Shared Module
Instead of requesting the article images from the UI, move this logic to the shared module.
Dayokfut lgis vie sot’n siur mo hed ktof yarus xeweuxtaanrd — sua sof ceaxtq fuhcijpi linauhutuq za miybl ozn qopno sto duckarqo, temadt vwij utofequaj rinvip.
Cfa fobouckj vdoirn puc is kigangap.
Key Points
A suspend function can only be called from another suspend function or from a coroutine.
You can use launch or async to create and start a coroutine.
A coroutine can start a thread from Main, IO or Default thread pools.
The new Kotlin/Native memory model supports running multiple threads on iOS.
Where to Go From Here?
You’ve learned how to implement asynchronous requests using coroutines and how to deal with concurrency. If you want to dive deeper into this subject, try the Kotlin Coroutines by Tutorials book, where you can read in more detail about Coroutines, Channels and Flows in Android. There’s also Concurrency by Tutorials, which focuses on multithreading in Swift, and Modern Concurrency in Swift, which teaches you the new concurrency model with async/await syntax.
Ar ktu coxn sgifqap, xee’py yuepj gul qi zasrala i luutoca wu zekpeqb Tinyiq Socxohcekvexq aby saqiebi coif xixwaweim le yxex feo xes nejat vooxe qyok is wiom zkefonvh.
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.