favetelinguis

favetelinguis

Message delivery order guarantees for GenServer

I know there is call and cast. The difference is that call blocks the caller until a reply is made and cast returns right away not blocking the caller. However the scenario im interested in is the following.

Given two processes A and B. A send two messages A1 and A2 to B and it want to send them as fast as possible but it must also guarantee that A1 is handled before A2 by B.

Now the problem I have with this is that if I use call A must wait until A1 is processed by B, I want to use the message queue of B to send messages. And if i use cast there is no order guarantees. A2 could get processed before A1.

What is the idiomatic Elixir code for this case?

First 3 of 3 Posts Switch mode

kokolegorille

kokolegorille

The order should be guarantee by B’s mailbox arrival order…

I do not think it is related to call or cast.

When You cast, You simply have no return message.

Where did You get this?

And if i use cast there is no order guarantees. A2 could get processed before A1.

favetelinguis

favetelinguis OP

That is just my guess since cast is async I assumed it did not have this guarantee… But it would be very nice if it has.

kokolegorille

kokolegorille

From Erlang’s doc

10.8 Is the order of message reception guaranteed?

Yes, but only within one process.

If there is a live process and you send it message A and then message B, it’s guaranteed that if message B arrived, message A arrived before it.

On the other hand, imagine processes P, Q and R. P sends message A to Q, and then message B to R. There is no guarantee that A arrives before B. (Distributed Erlang would have a pretty tough time if this was required!)

PS. It’s not the same async as in JS :slight_smile:

— All posts loaded —

Where Next?

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement