Day 13: Async
Lesson 0: Intro
I'm really sorry. We need to talk about something tricky.
You see, so far all of our code has been nice and sequential, do x, then y, then z etc. All nice and orderly, one operation after another.
The thing is, out there in the coding world, things are different. We might want to execute our code in a sensible and ordered manner, however there is something getting in our way.
Time is a problem as it slows us down, it slows our code down and gets in the way.
To get a better idea of what I mean, here's an example of what I'm talking about and why it's a problem.
Getting data across the internet takes time, you see this when loading a web page, content appears after a delay. Now computers run much, much faster than our brains do, so if we are seeing a delay imagine how much of a delay our computer is seeing. The processors inside our computers can do billions of things per second, so a half second delay could be hundreds of millions of wasted cycles. It would be nice if our computer could go off and do something else while waiting for that delay to wrap up.
Well, that's what async (asynchronous) means. It means that rather than completing every action one after another it will instead do things when it can and come back to other things later when they are ready so as to not waste time.
All the code you have written so far has been synchronous, if a line of code took a while to complete then your computer waited until it was done before executing the next line.