[erlang-questions] automatically delete older messages with the same tag (atom)?

Bernard Duggan <>
Tue May 5 23:12:38 CEST 2009


Hi Giorgos,
	I'd be surprised if there's some inbuilt way to do this - I certainly
have never seen one.
In terms of a code snippit to do it, something like this perhaps:

--------
main() ->
   Msg = receive_latest(none, infinity).

receive_latest(LastPayload, Timeout) ->
   receive
      {interesting_message, Payload} -> receive_latest(Payload, 0);
      after Timeout -> LastPayload
   end.
--------

Cheers,

Bernard


Giorgos Kollias wrote:
> Hello Erlang users,
> 
> Is there an option in the Erlang runtime to automatically delete a message
> that has been deposited into a process's mailbox as soon as a newer message
> with the same tag arrives? Is it easy to "patch" the Erlang language source
> code to support this "little" feature in case this is not there?
> 
> Or the only feasible way of getting this behavior is just to receive all
> messages till you get a sort of timeout and just keep the latest message
> with the tag you are interested in (i.e. user code only) in each receive
> phase? Is there a standard code idiom/snippet for this?
> 
> This feature would be very interesting for implementing the asynchronous
> iterations computing paradigm where each process only keeps the most
> up-to-date message when it looks into its incoming messages.
> 
> Thanks in advance,
> 
> giorgos
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list