Skip to content

Latest commit

 

History

History
executable file
·
189 lines (118 loc) · 8.05 KB

README.md

File metadata and controls

executable file
·
189 lines (118 loc) · 8.05 KB

Event loop 🔄 in JavaScript and rise of Asynchronous Behaviour.

Poster - HackOn

🔴 A webinar by HackOn Hackathon 🚀

YouTube Live

😕 Shall I watch?

That's a good question!

Do a self analysis of your JS knowledge, take a pause and predict the output for the below code snippet. 😯

If you're able to predict the correct sequence of log statements, I hope you need not watch the video, skip to the takeaways section. ✌️ If not, do watch the video and thank me later! 🤗


console.log('Hi!');

console.log('Hope you\'re staying safe at home!');

setTimeout(() => console.log('Turn your self isolation into self improvement!'), 1000);

setTimeout(() => console.log('Chant, Go Corona, Corona Go 😃'), 0);	

console.log('Thank You!');

5️⃣ Five Takeaways 💡

GitHub has maximum number of pull requests in JavaScript repositories. Check the live stats here.

  • JavaScript is single threaded, it simply means it has a single call stack.

  • The asynchronous behaviour is not part of the JavaScript language itself, rather they are built on top of the core JavaScript language in the browser (or the programming environment) and accessed through the browser APIs.

  • setTimeout(function, delay) does not stand for the precise time delay after which the function is executed. It stands for the minimum wait time after which at some point in time the function will be executed.


Take a look at the below code:

function goCorona() {
   console.log('Stay Home, Stay Safe');
}

setTimeout(goCorona, 5000);

That doesn’t mean that goCorona will be executed in 5s but rather that, in 5000 ms, goCorona will be added to the queue. The queue, however, might have other events that have been added earlier — the function goCorona will have to wait. The idea here is the above code gaurantees that Stay Home, Stay Safe will be printed anytime after 5000ms.


  • setTimeout returns timeoutID - The returned timeoutID is a positive integer value which identifies the timer created by the call to setTimeout(). This value can be passed to clearTimeout() to cancel the timeout.

  • The Event Loop has one simple job — to watch the Call Stack and the Callback Queue. If the Call Stack is empty, it will take the first event from the queue and will push it to the Call Stack, which effectively runs it.


About Me

// About me

import { Speaker } from 'HackOn';

let user =  {
      Name: 'Vinit Shahdeo',
      Company: 'Postman',
      Profile: 'Software Engineer',  // Ex VITian
      Twitter: '@Vinit_Shahdeo'
    },
    title: 'Event loop in JavaScript and rise of Asynchronous behaviour';

_.assign(new Speaker(), user, new Event(title));

Vinit Shahdeo

GitHub followers

Twitter Follow

Learn more about me here.

Well, in this unprecedented time, you all have showed interest. I thank all of you for joining me. 🤗 Stay Safe at home.

😷 🏠

/**
 * 
 * Let's fight for Corona together!
 */
function stayAtHome() {
  eat();
  sleep();
  code();
  repeat();
}

while(_.isAlive(new Virus('COVID-19'))) {
  // Stay home, Stay safe
  stayAtHome();
}

😕 Any doubts?

👉 You can find the PPT inside docs folder.

🔗 Click here to download the PPT.

🖋️ Feel free to shoot your doubts here.

  ___      _     ___  ___                  
 / _ \    | |    |  \/  |                  
/ /_\ \___| | __ | .  . | ___              
|  _  / __| |/ / | |\/| |/ _ \             
| | | \__ \   <  | |  | |  __/             
\_| |_/___/_|\_\ \_|  |_/\___|             
                                           
                                           
  ___              _   _     _             
 / _ \            | | | |   (_)            
/ /_\ \_ __  _   _| |_| |__  _ _ __   __ _ 
|  _  | '_ \| | | | __| '_ \| | '_ \ / _` |
| | | | | | | |_| | |_| | | | | | | | (_| |
\_| |_/_| |_|\__, |\__|_| |_|_|_| |_|\__, |
              __/ |                   __/ |
             |___/                   |___/ 

:bowtie: Checkout my recent works below:

GitHub stars - COVID-19 Vinit Shahdeo



// thank you :)

const THANK_YOU_MSG = `Thank you so much for being here! 
	you were an amazing audience`;

let sayThanks = (viewer) => { return THANK_YOU_MSG };

_.forEach(allViewers, function (viewer) {
	_.times(Number.MAX_SAFE_INTEGER, sayThanks(viewer));
});

Thank you for watching this

Twitter Follow GitHub followers