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.
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.
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.
very helpful artcile. can i copy that image (sync vs async diagram) for my presentation?
ofc