Gain an understanding of what asynchrony is and where we experience it in daily life in this video.
- [Instructor] The term asynchronous has technical applications in the field of programming. However, it also fundamentally describes experiences that we all go through every day. Now, asynchronous is the opposite of synchronous. When a set of things has to happen one after another, that's a synchronous process. For instance, imagine you go to the movies, and you get in line to buy a ticket. If there are three people in line in front of you, and just one cashier, you have to wait until each of the people in front of you buy their tickets before you can buy yours. That's a synchronous process, because you can't make your purchase until all the other purchasers who are queued up in front of you have been served. Synchronous processes are sometimes described as blocking, because the next step in the process is blocked from happening until the current step is finished. Now, instead of a movie ticket line, imagine you go to a sit-down restaurant. Now, if this worked synchronously, like our movie theater, you might wait in line behind everybody else who wanted to eat at the restaurant. There would be one table at the restaurant and one employee. They'd take the customer's order, go back to the kitchen and cook it, serve it to the customer, clear the table when the customer was finished, present the bill, take payment, and then prepare the table for another customer. This would never work for a restaurant, because preparing and eating a meal takes way too long for anyone to want to wait for their turn. Fortunately, restaurants work on an asynchronous model, in which multiple things can happen at the same time. So, if my friends and I sit down at a restaurant, a server might bring us a menu and take our drink order. Meanwhile, another server might be serving food to people at a different table. Just having multiple people working at the same time means that multiple things can happen at once. Multiple servers are taking and serving orders, the cooks are in the kitchen preparing meals, other people are busing tables and setting them. As a result, many people can be at different stages of ordering, eating, and paying simultaneously, with the blocking kept to a minimum.
- Defining asynchronous programming
- Building code using a callback
- Building code using promises
- Batching multiple promises
- Building code using async/await