[erlang-questions] How to write a generic IRC client the OTP way?

Jon Watte <>
Thu Jun 30 05:12:27 CEST 2011


A client would call gen_server:call(ircclient, {nick, ale}) to set the
nickname for example.
The "Erlang Way" is said to be to export actual functions (setnick, getnick,
...) from the gen_server module public API, and have those functions do the
gen_server calls. This means that you can change the gen_server message
format without breaking compatibility.

Also, for synchronous calls (where you want the status), waiting the
necessary amount of time is pretty much what you expect to do. You *can*
make arrangements to use cast, and pass in a respond-to-PID parameter as
part of the request, but in most cases, that adds significant extra
complexity for very little benefit.

Note that gen_server:call also takes a timeout parameter -- it defaults to
5,000 milliseconds, so if the gen_server is "wedged" then the timeout will
kick in.

Sincerely,

jw

--
Americans might object: there is no way we would sacrifice our living
standards for the benefit of people in the rest of the world. Nevertheless,
whether we get there willingly or not, we shall soon have lower consumption
rates, because our present rates are unsustainable.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110629/9765c81f/attachment.html>


More information about the erlang-questions mailing list