Browse Source

add blocking access for tokio feature.

ZRY 1 year ago
parent
commit
e81d52d02c
2 changed files with 9 additions and 1 deletions
  1. 1 1
      Cargo.toml
  2. 8 0
      src/tokio/mod.rs

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "simple-rw-global"
-version = "0.3.0"
+version = "0.4.0"
 edition = "2021"
 authors = ["ZRY <admin@>z-touhou.org"]
 

+ 8 - 0
src/tokio/mod.rs

@@ -106,4 +106,12 @@ impl<T> AsyncGlobalContainer<T> {
     pub async fn get_mut(&self) -> RwLockWriteGuard<GOption<T>> {
         self.content.write().await
     }
+
+    pub fn blocking_get(&self) -> RwLockReadGuard<GOption<T>> {
+        self.content.blocking_read()
+    }
+
+    pub fn blocking_get_mut(&self) -> RwLockWriteGuard<GOption<T>> {
+        self.content.blocking_write()
+    }
 }