Synchronous vs. Asynchronous Programs
Explore the differences between synchronous and asynchronous programming in Elixir. Learn how asynchronous code enables non-blocking operations and concurrency using the Task module. Understand how to run functions concurrently, improve performance, and retrieve results efficiently.
We'll cover the following...
Synchronous code
By default, when we run some code in Elixir, we have to wait for it to complete. We get the result as soon as the code finishes but cannot do anything in the meantime. The code is executed synchronously and is sometimes called blocking code.
Asynchronous code
The opposite of this is running code asynchronously. In this case, we ask the programming runtime to run the code but carry on with the rest of the program. Asynchronous code runs in the background because the application keeps running as if nothing happened. Eventually, we can retrieve the result when the asynchronous code finishes. Since asynchronous code doesn’t block the ...