Async patterns: Promises

Given our understanding of what async is, how the callback pattern manages async, and some of the deficiencies of the callback pattern, let’s dive into another, newer pattern — promises.

Promises are clearly exciting the JS community. As someone who never really knew JavaScript before promises, I have only an academic understanding of the magnitude of this shift. In fact, I think I was exposed to management of async first with callbacks to make promises seem just that much more awesome (like building a node server before meeting Express). Understanding both is important to a deeper understanding of each, individually.

As with callbacks, for a new developer, it can be difficult to sift through the massive amount of information available online. For the benefit of anyone else newly exposed to promises, in this post I’ve attempted to cull the resources and posts that I have found most enlightening through my own learning.

Continue reading Async patterns: Promises

What is asynchronous JavaScript?

When people talk about asynchrony in JavaScript, what do they mean? First, a real-world example of an asynchronous process (summarized here, and originally here).

Imagine you walk into a coffee shop to get a latte. If they’re busy, perhaps you wait in line. When it’s your turn, you place your order with the cashier, and pay for the drink. The cashier writes your order — maybe even your name — on a coffee cup, and places it behind the empty (not yet fulfilled) cup of the person who ordered before you. Perhaps the shop is quite busy and there are ten cups ahead of yours. That queue of yet-unfilled coffee cups allows for the separation of the cashier (processing and queuing orders) and the barista (fulfilling orders based on the information supplied by the cashier). This queuing process results in increased efficiency and output. (The original source expands on the metaphor and is quite interesting). This is an example of asynchronous, non-blocking behavior.

Continue reading What is asynchronous JavaScript?