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. However, for most Rust web frameworks, async rust is directly implemented for handling endpoints.
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 with other threads and the
main
program.
This...