1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00

add notes on sync primitives

This commit is contained in:
Nikolay Kim 2017-12-26 11:19:08 -08:00
parent 030a70841a
commit 5e17a846af
2 changed files with 11 additions and 5 deletions

View File

@ -1,7 +1,7 @@
# Handler # Handler
A request handler can by any object that implements A request handler can by any object that implements
[`Handler` trait](../actix_web/dev/trait.Handler.html#implementors). [*Handler trait*](../actix_web/dev/trait.Handler.html).
Request handling happen in two stages. First handler object get called. Request handling happen in two stages. First handler object get called.
Handle can return any object that implements Handle can return any object that implements
[*Responder trait*](../actix_web/trait.Responder.html#foreign-impls). [*Responder trait*](../actix_web/trait.Responder.html#foreign-impls).
@ -11,7 +11,7 @@ result of the `respond_to()` call get converted to `Reply` object.
By default actix provides `Responder` implementations for some standard types, By default actix provides `Responder` implementations for some standard types,
like `&'static str`, `String`, etc. like `&'static str`, `String`, etc.
For complete list of implementations check For complete list of implementations check
[Responder documentation](../actix_web/trait.Responder.html#foreign-impls). [*Responder documentation*](../actix_web/trait.Responder.html#foreign-impls).
Examples of valid handlers: Examples of valid handlers:
@ -115,6 +115,11 @@ fn main() {
} }
``` ```
Be careful with synchronization primitives like *Mutex* or *RwLock*. Actix web framework
handles request asynchronously, by blocking thread execution all concurrent
request handling processes would block. If you need to share or update some state
from multiple threads consider using [actix](https://actix.github.io/actix/actix/) actor system.
## Response with custom type ## Response with custom type
To return custom type directly from handler function type needs to implement `Responder` trait. To return custom type directly from handler function type needs to implement `Responder` trait.

View File

@ -6,8 +6,9 @@ Builder-like patter is used to construct an instance of `HttpResponse`.
`HttpResponse` provides several method that returns `HttpResponseBuilder` instance, `HttpResponse` provides several method that returns `HttpResponseBuilder` instance,
which is implements various convinience methods that helps build response. which is implements various convinience methods that helps build response.
Check [documentation](../actix_web/dev/struct.HttpResponseBuilder.html) Check [documentation](../actix_web/dev/struct.HttpResponseBuilder.html)
for type description. Methods `.body`, `.finish`, `.json` finalizes response creation, for type description. Methods `.body`, `.finish`, `.json` finalizes response creation and
if this methods get call for the same builder instance, builder will panic. returns constructed *HttpResponse* instance. if this methods get called for the same
builder instance multiple times, builder will panic.
```rust ```rust
# extern crate actix_web; # extern crate actix_web;