Let's say you have the following chores to do:
- Balance your checkbook
- Do 3 loads of laundry
- Cook a pie
If we did all of these tasks synchronously it would take a very long time. Balancing the checkbook might take 30 minutes, each load of laundry will need to go through a wash cycle (30 minutes), and a dry cycle (45 minutes), and cook a pie (15 minutes prep, 30 minutes baking). If we blocked on each task, it would go like this:
- 30 minutes checkbook
- 30 minutes x 3 loads = 90 minutes washing laundry
- 45 minutes x 3 loads = 135 minutes drying laundry
- 45 minutes making the pie
That's 5 hours if I did my math correctly! But we don't need to block (aka wait) for some of these processes. We can get them started and move on to another task. Let's say each load of wash is broken down as 5 minutes blocking and 25 minutes non-blocking, drying is 5 minutes blocking and 40 minutes non-blocking and the pie is 15 minutes blocking and 30 minutes non-blocking.
- 5 minutes load first wash
- 15 minutes pie prep
- 10 minutes on the checkbook (20 remain)
- 5 minutes load dryer
- 5 minutes load 2nd wash
- 10 minutes on the checkbook (10 remain)
- (remove the pie, let's call this 0 minute task for simplicity)
- 10 minutes on the checkbook
- 15 minutes idle (but we could be doing something useful)
- 5 minutes 2nd dryer load
- 5 minutes last wash
- 40 minutes idle
- 5 minutes last dryer load
- 40 minutes idle
We did it all in under 3 hours, and we had lots of idle time to watch our favorite HBO series.
That is all async/await really is. You aren't actually doing more than one thing at a time, but you can go on to do other things while something that doesn't need your attention is working.