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

Add simple state example #742

Merged
merged 2 commits into from
Nov 13, 2020
Merged

Conversation

joshtriplett
Copy link
Member

I found this example useful in understanding how a tide-based server can
handle and maintain state.

I found this example useful in understanding how a tide-based server can
handle and maintain state.
@joshtriplett
Copy link
Member Author

Re-pushed with formatting fixed.

@jbr
Copy link
Member

jbr commented Nov 12, 2020

Thanks! I think we'd probably want to encourage people to put the Arc inside of their State (struct State { value: Arc<AtomicU32> } and Server<State> instead of struct State { value: AtomicU32 } and Server<Arc<State>>), since often State will contain types that are already Clone, like database connection pools. Happy to be convinced that this is a better exemplar, though

@joshtriplett
Copy link
Member Author

joshtriplett commented Nov 13, 2020

@jbr Perfectly happy to do it that way instead.

(If you have multiple fields that need Arc, it may make sense to wrap all those fields in a single structure to use only one reference count and one atomic operation, but that structure could still be inside the outermost state structure.)

@jbr
Copy link
Member

jbr commented Nov 13, 2020

Thanks!

@jbr jbr merged commit 7a78ebe into http-rs:main Nov 13, 2020
@joshtriplett joshtriplett deleted the simple-state-example branch November 14, 2020 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants