Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding the Event Loop

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
Avatar for Okanlawon Emmanuel Okanlawon Emmanuel
September 29, 2018
32

Understanding the Event Loop

Avatar for Okanlawon Emmanuel

Okanlawon Emmanuel

September 29, 2018

Transcript

  1. Hello! I’m Okanlawon Emmanuel A Full Stack Web Developer ...

    Currently leading an amazing Team @ Obigtech
  2. Nodejs Nodejs is single Threaded and based on event model

    ,it’s more than a wrapper of v8, its provides API to interact with the Oper- ating System
  3. How does Node Work ? Nodejs is based on event

    Model and this model is organised by what’s called Event Loop Event loop brought about the Non-Blocking Nature of Nodejs it’s doesn’t mean we can’t write blocking code in Nodejs but should should be avoided.
  4. Slow I/O Operation slow i/o operations are handle with events

    and callbacks so that they don’t block the main execution runtime (Call Stack) Nodejs revolves around this concept. show example code in nodejs terminal
  5. what’s I/O ? it’s used to label the communication between

    the process of a computer CPU and anything external to that CPU in Node This is used to reference accessing disk or Network Resources which is the most time expensive part of most operation
  6. Handling Slow I/O Operations Generally, slow I/O can can be

    handle with the following - Synchronously (hold up other request ) - Fork() (new request new process) - Thread ( new request new thread ) - Event Loop
  7. Nodejs Use the Event Loop to handle request for slow

    I/O Operation without blocking the main single threaded execution runtime. This is the most important concept to understand about Nodejs
  8. The Event Loop Definitions Event Loop is the entity that

    handle external events and convert them into callback invocations Event Loop is the guy that summon event from the Event Queue and pushes thier callbacks to the Call Stack, with an order of operation which is referred to as the “phase” of the Event Loop
  9. - The event loop runs in a separate thread than

    the main execu tion runtime. - The Threadpool handles all Async - Nodejs EventLoop == Browser EventLoop Misconception
  10. - Event loop is what makes the asyncronous callback program

    ming style possible in Nodejs - Event Loop start automatically when a script is excuted - Event Loop will exit when their are no more callback to perfom on - Event Loop is on the browser and it’s similar to how Event Loop work in Nodejs but not the samething - You can make the Event Loop busy with process.stdin.re- sume() Things to know.
  11. Heap This is where objects are stored in memory, memory

    allocations gets memory to be allocated here Call Stack this is a list of function in a stack data structure (FILO) (visualise the call stack in action with loupe, what happen’s when there is an infinity loop ?) Heap and Stack are part of the run-time engine not Node itself Node API this provides an interface to interact with the Operating System eg doing I/O expensive tasks.
  12. Event Queue Just as the name inplies it queues event

    in a first in first out manner Event Loop this is a simple loop that loop between the event queue and the call stack.
  13. Visualizing the Event Loop with Loupe Although Loupe is meant

    to visualise the Browser Event Loop but thier some general principle both of them have. They both have single main execution thread They both have Event Queue Instead of Browser API we have Node API
  14. Reference Nodejs.org, Philip Roberts - what the heck is the

    event loop anyway, Samar Buna - Advance Node.js , Pramod Chandrayan- How does node js single threaded Mechanism Work, Wikipedia, Mr Olukumoro (OS lecturer,Yabatech) Shout-out Okanlawon Folashade, Ire Aderinokun, Prosper Otemuyiwa, Nwamba Christian, Princess Antia