Facebook Pixel
Searching...
English
EnglishEnglish
EspañolSpanish
简体中文Chinese
FrançaisFrench
DeutschGerman
日本語Japanese
PortuguêsPortuguese
ItalianoItalian
한국어Korean
РусскийRussian
NederlandsDutch
العربيةArabic
PolskiPolish
हिन्दीHindi
Tiếng ViệtVietnamese
SvenskaSwedish
ΕλληνικάGreek
TürkçeTurkish
ไทยThai
ČeštinaCzech
RomânăRomanian
MagyarHungarian
УкраїнськаUkrainian
Bahasa IndonesiaIndonesian
DanskDanish
SuomiFinnish
БългарскиBulgarian
עבריתHebrew
NorskNorwegian
HrvatskiCroatian
CatalàCatalan
SlovenčinaSlovak
LietuviųLithuanian
SlovenščinaSlovenian
СрпскиSerbian
EestiEstonian
LatviešuLatvian
فارسیPersian
മലയാളംMalayalam
தமிழ்Tamil
اردوUrdu
Async JavaScript

Async JavaScript

by Trevor Burnham 2017 98 pages
4
100+ ratings
Listen

Key Takeaways

1. JavaScript's event-driven architecture enables responsive, non-blocking applications

JavaScript code can never be interrupted, because events can be queued only while code is running; they can't fire until it's done.

Single-threaded by design. JavaScript's event loop allows it to handle multiple operations without blocking. When an asynchronous operation is initiated, JavaScript continues executing other code while waiting for the operation to complete. This enables responsive user interfaces and efficient I/O handling.

Events as building blocks. Asynchronous functions in JavaScript generally fall into two categories: I/O and timing. These functions queue up events to be processed when the current execution stack is empty. This model allows developers to write non-blocking code that can handle many concurrent operations without the complexities of traditional multithreading.

Callback-based programming. Instead of waiting for operations to complete, JavaScript uses callbacks to define what should happen when an operation finishes. This approach requires a different mindset compared to synchronous programming, but it allows for more efficient use of resources, especially in I/O-heavy applications like web servers or user interfaces.

2. PubSub pattern distributes events for cleaner, more modular code

PubSub makes it easy to name, distribute, and stack events. Anytime it makes intuitive sense for an object to announce that something has happened, PubSub is a great pattern to use.

Decoupling components. The Publish/Subscribe (PubSub) pattern allows different parts of an application to communicate without direct dependencies. Publishers emit events without knowing who will receive them, and subscribers listen for events without knowing who emitted them. This leads to more modular and maintainable code.

Flexibility and scalability. PubSub allows for easy addition or removal of event handlers without modifying the emitting code. This makes it simple to extend functionality or debug specific behaviors. Many modern frameworks and libraries, including jQuery and Node.js's EventEmitter, implement PubSub-like patterns.

Event distribution. PubSub is particularly useful for distributing events across an application. For example, a single user action might trigger updates in multiple UI components, model changes, and server communications. PubSub allows these responses to be defined independently, making the code easier to understand and maintain.

3. Promises simplify asynchronous operations and error handling

Promises are a bundle of things you want to happen when a process comes to an end.

Representing future values. Promises provide a standardized way to handle asynchronous operations. They represent a value that may not be available immediately but will be resolved at some point in the future. This abstraction allows for cleaner, more intuitive code when dealing with asynchronous tasks.

Chaining and composition. Promises can be chained together, allowing complex sequences of asynchronous operations to be expressed clearly. Methods like .then() and .catch() provide a way to handle both successful outcomes and errors in a structured manner. This eliminates the "callback hell" often encountered in deeply nested asynchronous code.

Error propagation. Promises automatically propagate errors through the chain of operations, making it easier to handle exceptions in asynchronous code. This is a significant improvement over traditional callback-based approaches, where error handling often requires repetitive checks at each step of an asynchronous process.

4. Flow control libraries like Async.js tame complex asynchronous workflows

If you have a flow control problem, the odds are very good that Async.js has a solution.

Managing complex flows. Libraries like Async.js provide high-level abstractions for common asynchronous patterns. They offer methods for running tasks in series, parallel, or complex combinations thereof. This simplifies the implementation of workflows that would be challenging to manage with raw callbacks or even Promises.

Standardized patterns. Flow control libraries standardize common async patterns, making code more readable and maintainable. For example, Async.js provides methods like .map(), .filter(), and .reduce() that work with asynchronous operations, mirroring the familiar array methods but for async workflows.

Performance and concurrency control. These libraries often provide fine-grained control over concurrency, allowing developers to limit the number of simultaneous operations. This is crucial for performance optimization, especially when dealing with I/O-bound tasks or rate-limited APIs.

5. Web Workers and Node.js clusters enable true parallel processing

Distributed computing has never been more fun.

Leveraging multiple cores. Web Workers in browsers and the cluster module in Node.js allow JavaScript applications to utilize multiple CPU cores. This enables true parallel processing, which is essential for computationally intensive tasks that would otherwise block the main thread.

Isolated execution environments. Workers run in isolated environments, without shared state. This eliminates many of the complexities associated with traditional multithreading, such as race conditions and deadlocks. Communication between workers and the main thread is handled through a message-passing interface.

Scalability for server-side applications. In Node.js, the cluster module allows a single server to handle more concurrent connections by spawning worker processes. This is particularly useful for scaling web servers to take full advantage of multi-core systems without the need for complex load balancing setups.

6. Asynchronous script loading optimizes page load times

Page load optimization is a rich subject on which whole books have been written, and script loading is just one factor.

Balancing speed and functionality. Asynchronous script loading allows web pages to load faster by deferring the loading and execution of non-critical scripts. This improves the perceived performance of web applications, allowing content to be displayed more quickly while scripts load in the background.

HTML5 loading attributes. The async and defer attributes provide browser-native ways to load scripts asynchronously:

  • defer: Loads the script while parsing continues, but defers execution until parsing is complete
  • async: Loads and executes the script asynchronously, as soon as it's available

Script loaders and module systems. Advanced techniques using JavaScript-based script loaders or module systems (like RequireJS) offer even more control over script loading, allowing for dependency management and conditional loading based on application needs.

7. Mastering asynchronous patterns is key to writing efficient JavaScript

Dealing with complex sets of events in an elegant way is still frontier territory in JavaScript.

Evolving best practices. As JavaScript applications become more complex, mastering asynchronous patterns becomes increasingly important. Understanding and effectively using callbacks, Promises, async/await, and other asynchronous patterns is crucial for writing efficient, scalable JavaScript code.

Balancing abstraction and performance. While high-level abstractions like Promises and async/await make asynchronous code easier to write and understand, it's important to understand the underlying mechanisms. This knowledge allows developers to make informed decisions about which patterns to use in different scenarios, balancing code clarity with performance requirements.

Continuous learning. The JavaScript ecosystem is constantly evolving, with new patterns and best practices emerging regularly. Staying informed about these developments and understanding when and how to apply them is essential for JavaScript developers aiming to write cutting-edge, efficient applications.

Last updated:

Review Summary

4 out of 5
Average of 100+ ratings from Goodreads and Amazon.

Async JavaScript receives mostly positive reviews, with readers praising its focused approach to asynchronous programming. Many find it informative and enlightening, highlighting its coverage of event queuing, promises, and web workers. Readers appreciate the book's concise nature and its ability to improve understanding of JavaScript's single-threaded model. Some criticize it for being outdated or lacking in-depth examples, but overall, it's recommended for those looking to enhance their JavaScript skills, especially in handling asynchronous operations and creating more responsive applications.

Your rating:

About the Author

Trevor Burnham is the author of "Async JavaScript," a book that has garnered significant attention in the programming community. Burnham's work focuses on tackling one of the most challenging aspects of JavaScript programming: asynchronicity without concurrency. His approach is described as narrowly focused but highly informative, providing readers with new insights on nearly every page. Burnham's writing style is noted for its accessibility, making complex topics easier to grasp. He incorporates cultural references and practical examples to illustrate his points. While some readers mention that certain examples could be more thoroughly explained, Burnham's expertise in the subject matter is evident throughout the book.

Download PDF

To save this Async JavaScript summary for later, download the free PDF. You can print it out, or read offline at your convenience.
Download PDF
File size: 0.55 MB     Pages: 9

Download EPUB

To read this Async JavaScript summary on your e-reader device or app, download the free EPUB. The .epub digital book format is ideal for reading ebooks on phones, tablets, and e-readers.
Download EPUB
File size: 3.24 MB     Pages: 9
0:00
-0:00
1x
Dan
Andrew
Michelle
Lauren
Select Speed
1.0×
+
200 words per minute
Create a free account to unlock:
Bookmarks – save your favorite books
History – revisit books later
Ratings – rate books & see your ratings
Unlock unlimited listening
Your first week's on us!
Today: Get Instant Access
Listen to full summaries of 73,530 books. That's 12,000+ hours of audio!
Day 4: Trial Reminder
We'll send you a notification that your trial is ending soon.
Day 7: Your subscription begins
You'll be charged on Nov 28,
cancel anytime before.
Compare Features Free Pro
Read full text summaries
Summaries are free to read for everyone
Listen to summaries
12,000+ hours of audio
Unlimited Bookmarks
Free users are limited to 10
Unlimited History
Free users are limited to 10
What our users say
30,000+ readers
“...I can 10x the number of books I can read...”
“...exceptionally accurate, engaging, and beautifully presented...”
“...better than any amazon review when I'm making a book-buying decision...”
Save 62%
Yearly
$119.88 $44.99/yr
$3.75/mo
Monthly
$9.99/mo
Try Free & Unlock
7 days free, then $44.99/year. Cancel anytime.
Settings
Appearance