<div dir="ltr">I don't think it is a good idea to separate the state maintenance from the real work that is happening, unless you have a strong reason for it. What happens if you separate them is that you are keeping a process just for state maintenance, and most of the time the gen_fsm process is going to be idle. Other drawback is that the worker process will have to constantly check the state machine to ensure that it doing work at the correct state. There is a chance of off state processing and it is hardware hungry.<div><br></div><div>There are places where you will separate the state maintenance, for instance many workers depending on a single state. At the low level gen_fsm and gen_tcp are just Erlang process, and what you are trying to do right now is good for what you are doing.</div><div><br></div><div>Theepan<br><div><br></div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 23, 2015 at 9:31 AM, Garry Hodgson <span dir="ltr"><<a href="mailto:garry@research.att.com" target="_blank">garry@research.att.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 9/22/15 3:02 PM, Roger Lipscombe wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 22 September 2015 at 18:37, Garry Hodgson <<a href="mailto:garry@research.att.com" target="_blank">garry@research.att.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
thanks to both of you for your quick and helpful answers.<br>
gotta love this list.<br>
</blockquote>
Both Theepan and Vance are correct in that this is a useful way to<br>
build this kind of thing. In fact, there's a good example (using a<br>
gen_server, rather than a gen_fsm) here:<br>
<a href="https://erlangcentral.org/wiki/index.php?title=Building_Non_Blocking_Erlang_apps" rel="noreferrer" target="_blank">https://erlangcentral.org/wiki/index.php?title=Building_Non_Blocking_Erlang_apps</a><br>
</blockquote></span>
very nice.<span class=""><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'd just add one point, though: I recently built something similar,<br>
and I found it simpler to separate the client into two processes: one<br>
gen_fsm to handle the state machine, and a separate gen_server to<br>
handle the decoding and framing.<br>
</blockquote></span>
i briefly considered that, but it wasn't obvious how to divide the<br>
work between the two. i'd be interested in how you did, if you'd<br>
care to elaborate.<br>
<br>
thanks<br>
<br>
</blockquote></div><br></div>