Elixir Concurrency example

Elixir Concurrency example
Average rating: 0
(0 votes)

Thanks! You’ve rated this material!

Despite, there’s not much projects in Elixir nowadays developed in Ukraine, we believe that Elixir’s features will make it very popular soon. That’s why we seriously considering the practical use of Elixir for JS developers and for Rubyists. One of the main reasons for that is Elixir concurrency. And today we are going to explore with you the Elixir Concurrency example and put it in practice. Are you ready?

We aim to download concurrently different prices and return a map with the latest prices. Let’s see this process step by step.

  1. Define a function ticker_url(product_id) to return the URL string for the given product.
  2. Defineget_price function using only our HTTPClient module instead of HTTPoison and Jason.
  3. Focus on making one single concurrent request, then scale to multiple requests.
  4. Have everything to write a compact concurrent get_prices(products)function, using Elixir pipes.
  5. The first Enum.map runs spawn_and_send_price(product_id) for each product, returning a list of pids.
  6. The second Enum.map takes the list of pids as input, running await(pid) for each pid. It then returns the list of results.
  7. Enum.into transforms the list of tuples , in a Map.

Try to get the prices multiple times and find more examples here.

Que is a job processing library in Elixir that we explored closer and we think it can be interesting to you too.

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
Kharkiv Otakara Yarosha 22, 61000, Kharkiv, Ukraine
Email info@syndicode.com