gen_statem and simple_one_for_one supervisor
Thu Nov 26 13:11:45 CET 2020
On Thu, Nov 26, 2020 at 03:00:46PM +0300, Stanislav Ledenev wrote:
> In my application I have simple_one_for_one supervisor for handling incoming
> external requests (HTTP). Each request has some command and its arguments.
> Each command has its own workflow and that is why commands handler is
> implemented as gen_statem. This gen_statem handles all commands and
> I don't like that kind of a code mess inside of it.
> I have two thoughts in my mind about resolving this problem, but I don't
> them either:
> 1. Create multiple simple_one_for_one supervisors, one for each type of
> I don't think that so many supervisors is a good idea;
> 2. Create "general" gen_statem for supervisor and multiple handling modules
> which then be passed as arguments to supervisor's init.
> I don't like general over general and so on (yuck!).
> Is there any elegant way to solve this kind of a problem and keep this nice
> pair of simple_one_for_one supervisor and gen_statem?
gen_statem can switch between callback modules, so you could have
one which simply identifies which kind of command it's meant to be
handling, and then switches to the appropriate callback module for
that command, with the 'change_callback_module' action.
Hugo Mills | If you're not part of the solution, you're part of
hugo@REDACTED carfax.org.uk | the precipitate.
PGP: E2AB1DE4 |
More information about the erlang-questions