Single Threaded Blocking
To understand asynchronous/concurrent/multi-threaded we need to start with the most basics and WHY we add so much complexity to the issue.
In the beginning there was only really Single Threaded Blocking applications. These are really simple programs, and more than likely, these are what you are writing right now.
To explain, I will use an analogy of a Pizza House.
Imagine your computer is a pizza house with a single employee. He has only had basic training.
You walk into the shop, talk with the employee, look at the menu and order a pizza.
Great. The employee walks into the back of the shop, puts a pizza in the over and stands next to the oven waiting for the pizza to cook.
You remember your wife doesn't like pineapples. You shout at the employee trying to get his attention to change your order. No dice. He will not budge from the oven (he fell asleep).
You get annoyed and leave.
Multi-threaded Concurrent Blocking
You go to the next pizza shop.
It has 4 employees.
You walk into the shop, talk with the employee, look at the menu and order a pizza.
He shouts (sends a message) to the other employees in the back to make you a pizza. They put one in the oven. He stands next to the oven, and sleeps.
You forget your wife has allergies to bacon. You tell employee A to cancel the pizza. He yells inside to the cook, wakes him up. The cook throws the pizza in the bin and puts a Kosher pizza in the oven. He falls back asleep promptly.
You wait, pizza is ready, you get a bill. Its massive (hiring too many staff, and half of them sleep on the job).
Single Threaded Asynchronous/Non-blocking
You go to the next pizza shop.
It has 1 employee.
You walk into the shop, talk with the employee, look at the menu and order a pizza.
He walks inside, puts a pizza in the oven. He then attaches the receipt (callback) to the pizza. He walks back out to the counter.
You remember your wife actually doesn't eat meat this month. You tell the employee, he goes inside, fixes the situation.
After the employee checks inside for a done pizza. He then reads the receipt (give this pizza to Bob).
You get cheap affordable and responsive pizza.
async
keyword, or a shorthand for "asynchronous"? The two aren't completely equivalent. – Ben Voigt