Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate the use of gen_statem as an alternative to gen_server for implementation #26

Open
doughsay opened this issue Jul 1, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@doughsay
Copy link
Member

doughsay commented Jul 1, 2020

We do a lot of manual state management that might be helped by using gen_statem. Also, the future desired features of things like "tap keys" require the use of timers and timeouts, which are supported as first class features in gen_statem.

@doughsay doughsay added the enhancement New feature or request label Jul 1, 2020
@amclain
Copy link
Member

amclain commented Jul 1, 2020

Here is a basic implementation trying out gen_statem as part of this investigation:
https://gist.github.com/amclain/67b43f73e3b15cc86f957b3c1019ba19

Reading through the OTP Design Principles for gen_statem, it looks promising for this use case. Timeouts (timers) are flexible and also managed under the hood, which on first impression looks like it shifts developer focus to the events and state transitions rather than low-level timer management.

Another cool thing gen_statem provides is the ability to swap out the callback module. This may turn out to be really helpful for AFK. I haven't tested it out yet, but what I've gathered from the docs, this feature would let us build modules dedicated to certain states, which is helpful when dealing with many complex states that need to be transitioned to. By swapping out the callback module during a state transition, the states and event handlers can be broken up into multiple modules (i.e. files), which hopefully makes it easier to maintain a system that deals with complex state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants