1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00

Updated other/data-factory to v4. (#518)

This commit is contained in:
Christopher Gubbin 2022-02-02 15:13:08 +00:00 committed by GitHub
parent 5cf5295ea9
commit 4174a4c62f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 11 deletions

View File

@ -4,8 +4,8 @@ version = "1.0.0"
edition = "2021"
[dependencies]
actix-web = "3"
actix-web = "4.0.0-beta.21"
num_cpus = "1.13"
redis = { version = "0.16.0", default-features = false, features = ["tokio-rt-core"] }
redis = { version = "0.19.0", default-features = false, features = ["tokio-comp"] }
# redis_tang is an redis pool for test purpose
redis_tang = "0.1"
redis_tang = "0.2"

View File

@ -1,15 +1,15 @@
## Usage:
This is an example on constructing async state with `App::data_factory`
# Usage:
This is an example demonstrating the construction of async state with `App::data_factory`
## Reason:
`data_factory` would make sense in these situations:
- When async state not necessarily have to be shared between workers/threads.
Use of a `data_factory` would make sense in these situations:
- When async state does not necessarily have to be shared between workers/threads.
- When async state would spawn tasks on `actix-rt`. If we centralized the state there could be a possibility the tasks get a very unbalanced distribution on the workers/threads
- When an async state would spawn tasks on `actix-rt`. If state was centralized there could be a possibility the tasks get an unbalanced distribution on the workers/threads
(`actix-rt` would spawn tasks on local thread whenever it's called)
## Requirement:
- `rustc 1.43 stable`
- `rustc 1.58 stable`
- `redis` server listen on `127.0.0.1:6379`(or use `REDIS_URL` env argument when starting the example)
## Endpoints:

View File

@ -15,13 +15,13 @@ async fn main() -> std::io::Result<()> {
.await
.expect("fail to build pool");
let pool = RedisWrapper(pool);
let pool = Data::new(RedisWrapper(pool));
HttpServer::new(move || {
let redis_url = redis_url.clone();
App::new()
.data(pool.clone())
.app_data(pool.clone())
// a dummy data_factory implementation
.data_factory(|| {
/*