Inthistutorial, whatwe'regonnabetalkingaboutis a sinkioorsink, Yo, dependingonwhichwayyouwanttosayit, I won't judgeotherpeoplewill, UhAndwhat a sinkioseforisfor a synchronousprogramming.
Soagain, there's noway I cancoverthisentirepackageinonevideo.
Um, oreven a fewvideosjustknowthedocksexist, Sosoanyways, rununtilcomplete.
Andthenwheneveryou'redone, um, youcanyoudo a loopdotclothes.
I'm actuallynot 100% confident.
Rununtilcompleteisgonnarequire a loopdotclothes, butwe'llgoforitalso, you'llsee a lotoftimesincode, it's goingtotrytodotheloopstuffexceptdosomelogging, notreally a pass.
I'm tryingtothink I think I thinkthisisRunabelowatthisstage, letmejustrunquick, seeifwehadthere.
Yeah, okay.
ItisOkay.
Soitisrunnobleatthisstage, butwehave a coupleofissues.
Thefirstthingis, anytimeyouyousendoff a coroutinetorun, youwanttomakesureyouwaitforthecoderoutinetofinish, especiallyifyou'regonnastartin a looporifyou'regonnaendyourcode.
Soifyou'rejustifyou'rewriting a scriptthathappenstouse a stinkyOh, ifyouhappentoneedtodothat, youwanttomakesureyou'vewaitedfortheresultsbeforeyouendthisscript, Um, orbutagainintheloop, especiallyifyoudon't wait, you'regonnayou'regonnareallyquicklydispatch a lotofcoderoutines.
SoSowhatdoweneedtodo?
Weneedtoawait.
Soweawaitprettymuchyou'regonnaawaitbatchesorsinglecoroutinestryingtothinkif I'm gonnasaysomethingwronghere, but I'm tryingtohaveaninstancewhereyouwouldn't wanttoeventuallyawaityourcoroutines.
Sotheproblemis, eventhoughthisis a coderoutine, everythinginhere, though, isstillsynchronouslikethere's reallynopointwhereweactuallyhaveNo I Oh, herewehavenoWell, okay, wehaveio, butnotnotlikehighlightin C i o.
Wewerejustrunningthistask.
Sointhiscase, thisis a booktask.
Thisisn't really a requestto a server.
What?
Wewaitfor a response, Andthenduringthat, waitfor a response, wecoulddosomethingelse.
Um, soinstead, what I'm gonnadoiswe'rejustgonnaadd a loo.
Andbasicallythefunkthatthatthereisthatwejustneverawait a asleepinthesamepain A synchronoussleep.
SoOkay, soatthispoint, we'vebasicallytheprogramis a synchronousWewerekindofdecidingwhetherwewanttouse 50,000 or 500,000 dependingonwhichwaywewanttorun.
Itdoesn't makeallthatbigof a difference.
Butaswe'veseenthesleepitself, evenifit's a very, verysmallsleep, you'repaying a slightpenaltyforthetradeoffthatyou'redoingthere.
Becauseagain, thisisallconcurrent.
ThisisnotparallelyourYouhavetostopandswitchtasks.
Sojustlikewhenyoustopyourruntotieyourshoe, that's a littleslowerthanifyouhadjustkeptrunning.
You'vegotbendingovertimetotieyourshoe, right?
UmsoSojustkeepthatinmind.
Now, um, I thinkatthispoint, we'vebasicallycoveredeverythingweneedtocover.
Butthere's a fewotherlittlethings.
Um, actually, I thinkthere's onemoreessentialthing.
Sofour D one, whichwashereallthenumbersdivisibleby 4 34,113 inthatrange.
Heretheyare.
Sothat's howyoucangetyourresults.
Sonextwhat I wanttodoistalkaboutwhathappenswhenwemakemistakes.
Sofirstofall, becausethere's a fewmistakesthatyou'rejustsimplygoingtomakewhenyou'rewriting a synchronousprogramming, I thinkthere's a view, sobutprobablythebiggestoneisisnotawaitingyouryourreturns.
Sowhatifweletmejustcommentoutthatrequestingof a resulthereandthen I'm goingtocommentout, uh, theawaitandthereturn.
Andthey'reoftentheThey'rejustgonenowandand, uhandsoatthispoint, So I guessifyoudon't closeyourloop, Soatleasthere, itwouldseemtosuggest I justwonderififthisiscomplete.
Somaybethat's a reason, though, whyyoushouldstillhavelukedotclothesevenifyouuserununtilcomplete.
Sotheothermajormistake, um I thinkisjustgettingusedtothesyntax.
Andifyoustartwritingdeaf, Mayit's like, Whatifweifwejustremove a sinkfrominfrontofdefinedmainVerysuddenlyyoucanalreadyseeSublimeistellingme, um, butifwegotorunthisboom, suddenlywehave a syntaxerror, rightit.
Andatleastififyourbrandnewtowritingworkingwith a sink, I oh, uh, you'regonnaprobablyforgettodo.
You'regonnafry, forgetthe A sinkatleastoneortwotimes, andthenyou'regonnatrytousethissortoflogichere, Um, andthenyou'regonnabeOh, whatwasthisintaxagain?
Andyou'reusingtherightsyntaxhere.
You'rejustnotusingtherightSyntexuphere.
I actuallykindofthink I haven't reallydecided, but I feellikeitshouldprobablypointbackuptothefunctionnameorsomethingorthatwhatshouldbe a coderoutinename.
Anyway, um, I thinkthat's enoughfor a quickintroto a sink.
I owe a producesomemorestuffon a sink.
Iomaybemaybedosomething a littlemoreprojectbasedthanjustrealbasiclikethis.
Thisisnotreallysuperpractical.
Um, butbasically, thecruxofthesituationisit's allabout a sink, a waitandsewn, sortofsomesortofwaytosuspendthingsagain.
Like I saidbefore, I thinkit's a Iot.
Http, I needtoopenup a searchbar a Iot, Http, which I'm prettysurehisthirdpartyitis.
Yes.
Soit's for a sink.
I Oh, butit's anHDTVclientserver.
Basically, foreight, uh, pagedfor a sink.
I owesoreally, reallycommontask.
Youweresayingbeforeforwhyyouwouldwant a synchronouslydothingsIsanythingwithWebbWebb, right?
AndAndsoifthat's yourgoalwith a single, soyoumightwanttouse a IotHttp?
Mostlybecause, um I thinkit's mostlyjustsoyoucanhavetheasynchronousclientpersonallybecauseotherwiseyouyouprobablyhave, oratleast a sessionandstufflikethat.
Soworkingthatoutandhavingeverythingbereally, trulyasynchronouswouldbe a lotofwork.