From 541d24fb2dd14033a5ddbfe7c8b71b3bfb5dc207 Mon Sep 17 00:00:00 2001 From: leon3s Date: Mon, 20 Jan 2025 09:02:31 +0100 Subject: [PATCH 1/3] fix/example: shared mutable state --- examples/application/src/main.rs | 1 + examples/application/src/mutable_state.rs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/application/src/main.rs b/examples/application/src/main.rs index 45bfa70..c2edf1b 100644 --- a/examples/application/src/main.rs +++ b/examples/application/src/main.rs @@ -6,6 +6,7 @@ pub mod config; pub mod scope; pub mod state; pub mod vh; +pub mod mutable_state; // #[ntex::main] diff --git a/examples/application/src/mutable_state.rs b/examples/application/src/mutable_state.rs index df43718..5fac908 100644 --- a/examples/application/src/mutable_state.rs +++ b/examples/application/src/mutable_state.rs @@ -1,6 +1,6 @@ // use ntex::web; -use std::sync::Mutex; +use std::sync::{Arc, Mutex}; struct AppStateWithCounter { counter: Mutex, // <- Mutex is necessary to mutate safely across threads @@ -18,9 +18,9 @@ async fn index(data: web::types::State) -> String { #[ntex::main] async fn main() -> std::io::Result<()> { // Note: app state created _outside_ HttpServer::new closure - let counter = AppStateWithCounter { + let counter = Arc::new(AppStateWithCounter { counter: Mutex::new(0), - }; + }); web::HttpServer::new(move || { // move counter into the closure From c3232dba4883d9305b66567296e31b32e006754c Mon Sep 17 00:00:00 2001 From: leon3s Date: Wed, 22 Jan 2025 09:55:54 +0100 Subject: [PATCH 2/3] fix/example: shared mutable state arc on mutex and fix ci build --- .github/workflows/rust.yml | 3 +++ examples/application/src/mutable_state.rs | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 776cdd4..9148f0b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -17,6 +17,9 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions-rust-lang/setup-rust-toolchain@v1.6 + - name: install deps + run: | + sudo apt-get install -y libsqlite3-dev - name: test examples run: | cd examples diff --git a/examples/application/src/mutable_state.rs b/examples/application/src/mutable_state.rs index 5fac908..8bfd325 100644 --- a/examples/application/src/mutable_state.rs +++ b/examples/application/src/mutable_state.rs @@ -2,8 +2,9 @@ use ntex::web; use std::sync::{Arc, Mutex}; +#[derive(Clone)] struct AppStateWithCounter { - counter: Mutex, // <- Mutex is necessary to mutate safely across threads + counter: Arc>, // <- Mutex is necessary to mutate safely across threads } async fn index(data: web::types::State) -> String { @@ -18,9 +19,9 @@ async fn index(data: web::types::State) -> String { #[ntex::main] async fn main() -> std::io::Result<()> { // Note: app state created _outside_ HttpServer::new closure - let counter = Arc::new(AppStateWithCounter { - counter: Mutex::new(0), - }); + let counter = AppStateWithCounter { + counter: Arc::new(Mutex::new(0)), + }; web::HttpServer::new(move || { // move counter into the closure From 2ac1eb8c0aa0bd894d0c82871d16ef72fc1244b4 Mon Sep 17 00:00:00 2001 From: leon3s Date: Sun, 2 Feb 2025 15:09:25 +0100 Subject: [PATCH 3/3] chore: dump version to 2.0.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a922715..7421c30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ntex-website", - "version": "2.0.4", + "version": "2.0.5", "private": true, "scripts": { "docusaurus": "docusaurus",