[erlang-questions] gen_server and the ! operator

Bernard Duggan bernie@REDACTED
Wed Apr 15 05:35:06 CEST 2009


ulf_A wrote:
> example:  myServer:findById(Id).
>
> I want to do is this:
>
> whereis(myServer) ! {Id}.
>   
For a start, whereis() finds a registered process name, not a module
name (which myServer seems to be based on the first example).  You need
to register your server process with a line like:

register(myserver_process)

then you can send to it with:

whereis(myserver_process) ! {Id}

or indeed the shorthand form:

myserver_process ! {Id}

However, generally the "right" way to send a message to a gen_server
(where you don't require a response) is to use gen_server:cast().

Cheers,

Bernard



More information about the erlang-questions mailing list