Event
Events are occurrences or actions that a program can respond to. They can be triggered by user actions, system notifications, or program state changes.
Frontend (Browser) I/O Event Examples:
- User interactions: clicks, key presses, form submissions
- DOM changes: element loaded, attribute modified
- Network: AJAX request completed
- Timers: setTimeout, setInterval completions
Backend I/O Event Examples:
- File system: file read/write completed
- Network: incoming HTTP request, database query finished
- Inter-process communication: message received
- Timers: scheduled task ready
Non-blocking model
The non-blocking model allows a program to initiate I/O operations without waiting for them to complete before moving on to the next task.
Key characteristics:
- Asynchronous operations: Tasks that might take time are started and control immediately returns to the program
- Callbacks or Promises: Used to handle the results of asynchronous operations when they complete
- Efficient resource utilization: The program can perform other tasks while waiting for I/O operations
So what is an event loop
The event loop is a programming construct that waits for and dispatches events in a program.
How it works under the hood:
1. Initialization