Asynchronicity

Synchronicity vs Asynchronicity

Sync vs Async Demo

Synchronous

Asynchronous

setTimeout

setTimeout Demo

setInterval

setInterval Demo

More Theory

Threading

Threading Demo

Kitchen Analogy

Single vs Multi Threading Kitchen Analogy
Single vs Multi Threading Kitchen Analogy

Stacks and Queues

Stack vs Queue
Stack vs Queue

Call Stack

Call Stack Demo

Event Loop

Event Loop

User Input In Node

User Input In Node

// use terminal for input and output
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

readline Documentation

EOD

EOD Lecture Notes

Learning Objectives

  1. Identify JavaScript as a language that utilizes an event loop model
  2. Identify JavaScript as a single threaded language
  3. Describe the difference between asynchronous and synchronous code
  4. Execute the asynchronous function setTimeout with a callback.
  5. Given the function function asyncy(cb) { setTimeout(cb, 1000); console.log("async") } and the function function callback() { console.log("callback"); }, predict the output of asyncy(callback);
  6. Use setInterval to have a function execute 10 times with a 1 second period. After the 10th cycle, clear the interval.
  7. Write a program that accepts user input using Node’s readline module