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

State Management #178

Closed
Totodore opened this issue Nov 26, 2023 · 0 comments · Fixed by #194
Closed

State Management #178

Totodore opened this issue Nov 26, 2023 · 0 comments · Fixed by #194
Labels
enhancement New feature or request

Comments

@Totodore
Copy link
Owner

Totodore commented Nov 26, 2023

Currently there is no global state management for socketioxide so it is quite frustrating to manage state.
Most of the time it is needed to make a global OnceCell or something like that and then getting the state from the Cell each time it is required.

Because of the current architecture with the imbricated closures it is not possible to adopt the "Axum" way of managing state which is having only one typed field on handlers and then using a State extractor to extract it. It has many advantages because it allows to have State type checking at compilation and it is quite efficient.

The remaining way of achieving state management in socketioxide is to have either one dynamic OnceCell or a TypeMap stored in the Client and an extractor that extract the corresponding data. In case of failure it would not call the handler and a tracing error would be logged.

Things to do are :

  • Add a state module and a state struct with a dynamic TypeMap but only with creation fn (no mut ref). (behind a feature flag)
  • Add a field in the client module for the state struct (behind feature flag)
  • Pass a state reference to every handlers
  • Create a State extractor that would extract a given state from the TypeMap
@Totodore Totodore added enhancement New feature or request help wanted Extra attention is needed labels Nov 26, 2023
@Totodore Totodore linked a pull request Dec 5, 2023 that will close this issue
@Totodore Totodore removed the help wanted Extra attention is needed label Dec 5, 2023
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
1 participant