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
Example for registering data is incomplete and fails in the obvious use case #1033
Comments
Same issue here, solution below. This applies to the Shared Mutable State section under Basics | Application in the docs. It is not clear where the user should put the app data. The example should be something like this (note the "move" when creating the HttpServer):
Note to reader: See Extractors | Async Data Access section for an explanation about the dangers of using a mutex in an async handler. Your application becomes single threaded while the mutex is held and awaiting inside one of these locks is particularly bad because it can lead to deadlocks. |
@Lindenk where is that example from? Actix-web went through a lot of changes, so some examples could be outdated |
Thanks @Lindenk, I figured it out from the state example. This is indeed a case of outdated docs. See |
I just filled a ticket regarding this documentation issue actix/actix-website#109 |
Here's the example for adding application data to the server:
And here is the example for running a server:
The first example does not include
HttpServer
, doesn't bind to a port, and doesn't serve an application. Attempting to wrap theApp
in anHttpServer
meansweb::Data<T>
must beSend
. Apparently, it also forcesT
inweb::Data<Arc<Mutex<T>>>
to also beSend
instead of using the wrapped value.Here's a direct example of the problem:
The text was updated successfully, but these errors were encountered: