DEV Community

Cover image for Understand Asynchronous Tasks with Coffee Shop Example ☕
Mangabo Kolawole
Mangabo Kolawole

Posted on

Understand Asynchronous Tasks with Coffee Shop Example ☕

Asynchronous programming is a form of parallel programming that allows a unit of work to run separately from the primary application thread.

When the work is complete, it notifies the main thread.

Let's take a real-life example to better understand the concept.

Coffee Shop Example

  • Jack: Hi. Please can I have a coffee? (First asynchronous task)

  • First barista: For sure. Do you want something else?

  • Jack: A piece of cake while waiting for the coffee to be ready. (Second asynchronous task)

  • First barista: For sure.

( Launch the preparation of the coffee )

  • First Attendant: Anything else?

  • Jack: No.

  • First barista: 5 dollars, please.

  • Jack: Pay the money and take a seat.

  • First barista: Start serving the next customer.

  • Jack: Start checking Twitter while waiting.

  • Second barista: Here's your cake. (Second asynchronous task call returned.)

  • Jack: Thanks!

  • First barista: Here's your coffee. (First asynchronous task call returned.)

  • Jack: Hey, thanks! Take his stuff and leave.

To make it simple, while you are waiting for someone else to do something for you, you can do other tasks or ask others to do more things for you.

This is basically asynchronous process.

Article posted using bloggu.io. Try it for free.

Latest comments (2)

Collapse
 
sm0ke profile image
Sm0ke

Niceeee 🚀🚀

Collapse
 
koladev profile image
Mangabo Kolawole

Yay 🚀