Lesson 14To go further, some code practices
- Notion 86 - Introduction to eco web design code practices with The Good Manager project
- Notion 87 - Clean code for energy efficiency
- Notion 88 - Asynchronous code: do more, in less time
- Notion 89 - More efficient and less resource-intensive servers
- Notion 90 - Manage your server workload
- Notion 91 - Using external libraries: the example of Bootstrap CDNs
- Notion 92 - Code practices review
Notion 88
Asynchronous code: do more, in less time
Target skills
What is asynchronous code
An asynchronous code is a piece of code being executed on a particular event. For example, clicking on a button can be seen as an event. It will trigger the execution of the button action.
The other advantage of asynchronous code, is that it is being executed at the same time of the rest of the program. It will not block other actions and allow for interactivity.
Why is it more efficient
By conditioning the execution of a piece of code and running it in parallel of the main code, we can have code executed only when needed, and without blocking the whole program.
A program making a request to a server will use an asynchronous function: it will be triggered by an event, and start asking a server for information. While the server is responding (it can take some time!), the program will not be blocked while it waits for an answer.
Asynchronous functions allow several actions to take place at the same time, without the program being blocked or overloaded if the expected condition never occurs.