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

Ale peralta.alejandro@REDACTED
Thu Jun 30 04:06:54 CEST 2011

Hello All,

As a learning experience I want to make a generic IRC client. My
question is regarding the path to genericness, what would be the right
way to do this, or the OTP way?

At first I thought that I could use gen_server to hide logic there. A
client would call gen_server:call(ircclient, {nick, ale}) to set the
nickname for example. Since call is synchronous, and setting the nick
in irc, might take a couple of (micro)seconds, the process calling
will have to wait until it receives an answer and the client (calling
gen_server) might loose some interactivity (or the ability to do
something else while the response of the "NICK" irc command comes

The next thought was to use gen_server:cast(ircclient, {nick, ale}),
but then how would the client would get the response? As far as I
understood there is no way to get a deferred reply from gen_server.
The calling process has to wait, even if we use gen_server:call with
norepley and then gen_server:reply (which as far as I understood it is
useful, when making the gen_server container or process non blocking).

I could pass a callback function to gen_server:call, like this
gen_server:cast(ircclient, {nick, ale, fun CallbackFun/1}), and
CallbackFun takes the result and does something with it. This migh
work, but then that doesn't look very "OTP" to me.

This is what I'm having trouble the most understanding if "gen_*"
processes can call back in a deferred manner to the client using the
"gen_*" process.  "Hey gen_server, call me back when you get this

Probably my design is wrong?

Finally researching a bit, I thought that it might be a good idea to
write a behaviour. But the same question comes up, how do I callback
the client? (diagram: http://i.imgur.com/6N6Je.png)

Hopefully I explained my problem, and questions.



More information about the erlang-questions mailing list