[erlang-questions] Sending a message to all linked processes

John M. Nordgaard archevis@REDACTED
Fri May 30 08:36:13 CEST 2008


>> Hi all,
>>
>> Been looking through the documentation in search of an answer, and have
>> not been able to locate one, so I hope I haven't missed the obvious
>> here... my Erlang mileage is still nothing to brag about. :-)
>>
>> I was wondering if there is a simple and straightforward way to send a
>> message to all linked processes. Now, I am aware that a process exit
>> signal is transmitted in a functionally similar manner, so it seems that
>> at least some form of "broadcast to all linked processes" operation
>> exists
>> within the runtime. But is it possible to invoke such functionality
>> directly from source code?
>
>
> send_links(Message) ->
>     {link,Links} = process_info(self(), links),
>     lists:foreach(fun (P) -> P ! Message end, Links).
>
> Robert

Except for a minor typo (links, not link, in line 2) this solution seems
to work like a charm... :-)

Thanks, Robert!

- john.





More information about the erlang-questions mailing list