Why Task.async_stream is Cool thing for Enumerable in Elixir?

 

* To implement concurrent process in elixir programming on enumerable, async_stream is very useful.

* It returns stream of data after processing on the given enumerable in the given module and function.

* Each process is linked with the current process. If any crashes in that child process will break the current process. To start async_stream with no link to current process use async_stream_nolink.

* Initially lets us see what Elixir does and how it unites many features which are great.

* It offers a great concurrency system through the actor model

* It comes with fault tolerant: If an error occurs? Okay, let’s crash the process and let the

* Elixir supervisors restart everything that is needed.

* It is immutable. Regardless of how many bugs occur because some state is manipulated even though it is unexpected.

* It has an enumerable library for web sockets (though obtained from Erlang)

* Elixir is designed to make things happen. It is pragmatic in nature.

* A wonderful backbone is via framework called Phoenix.

Yes, I know that you can find all of these things in other programming languages as well. But usually not compiled in a single language.

Here let’s see what is the most common uses of tasks is to convert sequential code into concurrent code with Task.async/1while keeping its semantics. When initiated, a brand new process will be formed, coupled and tracked by the caller. Once the task action finishes, a message will be sent to the caller with the result.

There are two important things to consider when using async:

If you are using async tasks, you must awaita reply as they are always If you are not expecting a reply, consider using Task.start_link/1 detailed below.
async tasks link the caller and the spawned process. This means that, if the caller crashes, the task will crash too and vice-versa. This is on purpose: if the process meant to receive the result no longer exists, there is no purpose in completing the computation.
If this is not desired, use Task.start/1 or consider starting the task under a Task.Supervisor using async_nolink or start_child.

Supervising Enumerable Asynchronously

These tasks are able to supervised by the Supervisor. Initially supervisor started with no child specification. Dynamically child will be created under this supervisor.

Limit your Concurrency

We are able to limit the concurrency of the process. It defaults to maximum no of cores in the system. It will be limit by max_concurrency option.

No Need to Await

There is no need to await to receive the data after processing. It will await itself when calling the async_stream function. The stream of data is return as a result after completion of concurrent process.

Iteron sufficed the gap in using Elixir and our service in exemplary. We do respect our ideas and put up on effort to make our idea in live.

Wanna looking for a project developers in Elixir. Do have a chat with us.

Have project in mind!!! Get a free proof of concept.

Leave Comment

Your email address will not be published. Required fields are marked *