Understanding asynchronous programming
Up until this chapter, we have been writing code in a sequential manner. This is good enough for standard scripts. However, in web development, asynchronous programming is important, as there are multiple requests to servers, and API calls introduce idle time. In some other languages, such as Python, we can build web servers without touching any asynchronous concepts. While asynchronous concepts are utilized in these web frameworks, the implementation is defined under the hood. This is also true for the Rust framework Rocket. However, as we have seen, it is directly implemented in Actix Web.
When it comes to utilizing asynchronous code, there are two main concepts we must understand:
- Processes: A process is a program that is being executed. It has its own memory stack, registers for variables, and code.
- Threads: A thread is a lightweight process that is managed independently by a scheduler. However, it does share data, code,...