[erlang-questions] Erlang and Akka, The Sequel

Fred Hebert mononcqc@REDACTED
Fri Apr 3 20:30:43 CEST 2015

On 04/03, ayodele abejide wrote:
>There is an  implementation of Future/Promise in Elixir its called Task[1]

>Reading the source[2] Task is a wrapper around proc_lib that monitors 
>calling process for error handling and uses patterns described by Joe in
>its implementation. Understanding the primitives would make implementing
>something similar in Erlang trivial

Interestingly enough, this shows these patterns are harder to implement 
correctly than it seems. Looking at the code, if the caller process is 
trapping exits (process_flag(trap_exit, true)), then the caller won't 
only receive the 'DOWN' message sent by the monitor, but also an 'EXIT' 
tuple. If the `await` function is wrapped in a `catch`, then the message 
won't be handled properly.

The Elixir solution conveniently ignores that possibility in await() and 
therefore risks leaking messages (that will remain stuck in the process 

The Erlang RPC mechanism handles that one properly by spawning [1] a 
middle-man process to handle these failures [2].


The basic pattern is simple enough, but fault-tolerance is often 
trickier than one expects it to be.


More information about the erlang-questions mailing list