Understanding Async Programming with Starbucks

Helpful post to get a better understanding of Asynchronous programming.

Full article is here


've worked and trained with many developers over the years, and I found that many people struggle to get their head around asynchronous programming. Asynchronous structures like Futures, Promises and Blocks are literally everywhere now. Yet, they're still difficult to understand, so I thought I can help you wrap your head around it with some help from Starbucks. That said, grab your Pumpkin Spice Latte and get ready for a Caffeine-fueled adventure through the world of Async programming ☺

Pre-Starbucks - The Synchronous Model

Let's take a moment to picture yourself in line at your favorite coffee store, where they can process only one transaction at the time. You get to the counter, what happens next?

  • You put in an order for a quadruple espresso (it's going to be a long day ahead)
  • You pay the extortionate price (when did coffee get so expensive?!)
  • You stand still...
  • While you stand your server goes and crushes some beans;
  • You stand still...
  • The barista turns some handle's, bangs a big metal thing loudly, steams, froth;
  • You stand still...
  • Everyone behind you stands still...
  • The barista holds the little paper cup under the coffee machine as it pours your drink in;
  • Everyone behind you waits, checking their phones/watches, wondering who the awkward person ordering a quadruple espresso is;
  • Finally, the barista gives you your coffee;
  • You grab your drink; add any additions of your choice and leave;
  • Now the Server moves on to the next person, who orders a single bottle of water they've been holding the entire time, they pay and leave immediately!

Welcome to the world of synchronous programming! You ask a function to do something and you wait until they've done it. And if someone else wants to do something that could be much quicker, they have to wait!

Read the rest here ...