Re: gen_statem and simple_one_for_one supervisor
Stanislav Ledenev <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CAOkK=A+r1dLSmq_w0CUmPTwm2jk7DLs1tGYvHog+rptN=e1+Qg@mail.gmail.com> |
Oh, thank you very much! 'change_callback_module' action is relatively new and I was not aware of it. чт, 26 нояб. 2020 г. в 15:11, Hugo Mills <[email protected]>: > On Thu, Nov 26, 2020 at 03:00:46PM +0300, Stanislav Ledenev wrote: > > Hi, > > 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 > > like > > them either: > > 1. Create multiple simple_one_for_one supervisors, one for each type of > > command. > > 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. > > -- > Hugo Mills | If you're not part of the solution, you're part of > hugo@... carfax.org.uk | the precipitate. > http://carfax.org.uk/ | > PGP: E2AB1DE4 | >