Sync vs Async

In programming, synchronous operations block instructions until the task is completed, while asynchronous operations can execute without blocking other operations.

Examples of asynchronous operations are push notifications, click events, keyboard input or fetching data. Because they happen any particular time outside the main execution of your app.

Example of synchronous operations is your program itself. Like the main execution, everything that you run, runs in synchronous manner. That is one after another.

Cypress Asynchronous Nature and How does it differ from Synchronous?

Perhaps a better visual representation is a pizza restaurant.

Synchronous

Multiple customers are in line. The first customer walks up to the desk and orders a pizza. The chef puts the pizza in the oven and says it will be done in 20 mins. They both wait 20 mins and the customer pays and leaves. The next customer in line walks up and places his order.

Asynchronous

Multiple customers are in line. The first customer walks up to the desk and orders a pizza. The chef puts the pizza in the oven and says it will be done in 20 mins. The chef hints to the next customer in line to place his order while the pizza is in the oven.

Hawai pizza: een knapperige pizza met frisse ananas - New York Pizza

Don’t get this mixed up with multi-threading. Introducing a new thread introduces another chef in the restaurant. While this may work for restaurants like subway where each chef can create they own sandwich but for the pizza restaurant there isn’t much to gain since both pizza’s need to wait 20 mins.

2 Comments

Add a Comment

Your email address will not be published.