Whydo I needtothinkaboutthisstuffwhileridingJavaScriptcodeandmoreso 100 feetfrom a beautifulbeach?
Well, I cansympathize.
I'vewrestledwithmotivatedmyselftodigintotheselowerleveldetailsbefore, and I'd liketooffertomotivatingideas, maybeenoughtogetyouoverthepostalonchumpfirst.
Whenyouopen a fileornetworkconnection, theOSreturns a numberthatidentifiesthestreamcalled a filedescriptoryoucanusethat f d toreferencethestreamandothersystemcalls.
So, inthisexample, ifanoperationwouldblockthenonblocking, readreturnsanerrorinstead.
ThisiswhereLibya V comesinLibya, theabstractsoverthevaryingimplementationsofeventdrivenIoindifferentoperatingsystemsandprovides a commoninterfaceforthem.
Libby V isusedbynote, whichwillbeusingasourexampleJavaScriptruntimeInthefutureoftheslides, I'm guessingtheremaybe a fewLibya v developersintheaudiencetoday.
Libby V usestheoperatingsystemseventdrivenIoconstructstoe, waitforeventsandwhensomethinghappens, liveTVthenexecutestheregisteredcallbacksandresumeswaiting.
Thisiscalledanevent, Luke, andhere's anexampletomake a networkconnection.
WeinitializewhatLibby V calls a handle, whichrepresentssomekindofioobjectwecanperformoperationson.
Whenweopenedthenetworkconnection, wepassedliveYouve a callbacktorunwhentheconnection's established.
TotracktheseIoevents, Libya V tellsLennoxit's interestedinwhenthesocketbecomesrideable, thenLibyatheweightsaswell, lockinguntil a timeoutwherethenexteventhappens.
Butthoseinterruptscomein, theygetstoredandcuteup, andthentheLenoxschedulerruns a cutethequeueofunblockedprocesses, andthenit'llcontinueonitswayuntilthenextinterruptcomesalong.
Andmaybeifthere's absolutelynothingtodiotheLenoxscheduleorwillissue a halt, construction, whichwillturnofftheCPU, wereturnedoffpartsofit.
IfyousquintboththeoperatingsystemandnoGSappeartobedoingkindofsimilarthingshere, theoperatingsystemenablesprogrammerstowritelinearblockingIo, whereasnoJessenablesdeveloperstowritesequencesofIousingcallbacksor a singleweightcode.
There's anadditionalvirtualizationlayer, whichprovides a virtualCebutoouroperatingsystem.
Called a hypervisor.
Thehypervisorhasitsownscheduleer, whichallocatesCPUand I, oh, timebasedonhowmuchyou'repayingforyouractuallyrunningandevenmoreschedulersthanyouthought.
However, ifyourfrontendcodeisrunningon, react 16 orlater, yourdomrendersaresubjecttoanadditionalscheduleortwocalledreactfiber, becausetheeventloopdoesn't have a waytopreemptcontrolfromJavascriptwhenit's takingtoolong.
Sohere's like a broadoverviewofthemanylayersofourstackwhenwe'reworkingbothinbackandJavaScriptandinfrontofJavaScript.
There's a lotoflayershere, andthere's a tendencyforustothinkofhighlevelprogramminglanguageslikeJavascriptaslessefficientbecausetheyintroduceadditionallayersofoverheadandgiveuslesscontroloverthe, uh, theexecution.
I wanttoleaveyouwithmorenuancedideathanthat.
Aswe'veseenwithwaiting, workingat a highlevelofabstractionoftenleavesyouwith a clearerexpressionofwhatyou'rewriting.
AwesomeResourceisSamRobertshastalkonhowcloseshowsupclose, howLibya V isusedtocreatetheJseventloopandexposesthetradeoffsthataremadeindesigningit.
CindySTHoran's talkonnonblockingIodivesdeeperintohowtheoperatingsystemimplementseventdrivenIointernallyandfinally, MerrickMinkowski, EastLogSirisonselectwalksthroughthehistoryofhow I owemultiplexingevolvedstartinginearlycomputersystemsin a timebefore, peoplewerejustfiguringoutin a timewhenpeoplewerejustfiguringouthowtowritenetworkcomputerslikethedawnoftheInternet.
It's reallyfascinatingstuff, and I highlyrecommenddivingin.