From 4174a4c62f9d197bb0729a0690002085c51bd431 Mon Sep 17 00:00:00 2001 From: Christopher Gubbin <44929740+cgubbin@users.noreply.github.com> Date: Wed, 2 Feb 2022 15:13:08 +0000 Subject: [PATCH] Updated other/data-factory to v4. (#518) --- other/data_factory/Cargo.toml | 6 +++--- other/data_factory/README.md | 12 ++++++------ other/data_factory/src/main.rs | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/other/data_factory/Cargo.toml b/other/data_factory/Cargo.toml index dba27f46..8de28c97 100644 --- a/other/data_factory/Cargo.toml +++ b/other/data_factory/Cargo.toml @@ -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" diff --git a/other/data_factory/README.md b/other/data_factory/README.md index 98c31e07..7ead31d9 100644 --- a/other/data_factory/README.md +++ b/other/data_factory/README.md @@ -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: diff --git a/other/data_factory/src/main.rs b/other/data_factory/src/main.rs index 0dcae4d4..2a647397 100644 --- a/other/data_factory/src/main.rs +++ b/other/data_factory/src/main.rs @@ -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(|| { /*