[erlang-questions] Erlang and Akka, The Sequel

ayodele abejide <>
Fri Apr 3 23:05:03 CEST 2015


Fred,

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

You are right, the Elixir implementation actually breaks when any receive
block that consumes all messages off the queue is placed in-between the
async and await calls.

I submitted an issue.



Abejide Ayodele
It always seems impossible until it's done. --Nelson Mandela

On Fri, Apr 3, 2015 at 1:30 PM, Fred Hebert <> wrote:

> 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 the
>> 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
>>
>> https://github.com/elixir-lang/elixir/blob/v1.0.3/lib/
>> elixir/lib/task.ex#L146-L209
>>
>
> 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
> mailbox).
>
> The Erlang RPC mechanism handles that one properly by spawning [1] a
> middle-man process to handle these failures [2].
>
> [1]: https://github.com/erlang/otp/blob/maint/lib/kernel/src/rpc.
> erl#L629-L649
> [2]: https://github.com/erlang/otp/blob/maint/lib/kernel/src/rpc.
> erl#L328-L361
>
> The basic pattern is simple enough, but fault-tolerance is often trickier
> than one expects it to be.
>
> Regards,
> Fred.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150403/07456f04/attachment.html>


More information about the erlang-questions mailing list