Synchronous vs Asynchronous Work
Synchronous code executes as part of the current call stack. Asynchronous APIs allow work to be initiated without forcing the current JavaScript execution to wait for completion. The actual mechanism depends on the host environment.
Asynchrony does not mean JavaScript suddenly executes multiple JavaScript statements simultaneously on the same agent. Instead, completed asynchronous operations schedule callbacks or promise reactions to be processed later.
Asynchronous Scheduling
Key Takeaways
- Asynchronous APIs prevent the current operation from waiting unnecessarily.
- Completion callbacks run later.
- Asynchrony and parallel JavaScript execution are different concepts.
Knowledge Check
Does an asynchronous API necessarily mean JavaScript executes two pieces of JS simultaneously on one event-loop agent?