|
@@ -87,6 +87,10 @@ impl<T> AsyncGlobalContainer<T> {
|
|
|
*self.content.write().await = GOption::Some(obj);
|
|
|
}
|
|
|
|
|
|
+ pub fn blocking_set(&self, obj: T) {
|
|
|
+ *self.content.blocking_write() = GOption::Some(obj);
|
|
|
+ }
|
|
|
+
|
|
|
pub async fn is_empty(&self) -> bool {
|
|
|
let v = self.content.read().await;
|
|
|
match v.deref() {
|
|
@@ -95,8 +99,16 @@ impl<T> AsyncGlobalContainer<T> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- pub async fn manual_drop(&self) {
|
|
|
- *self.content.write().await = GOption::None;
|
|
|
+ pub fn is_empty_blocking(&self) -> bool {
|
|
|
+ let v = self.content.blocking_read();
|
|
|
+ match v.deref() {
|
|
|
+ GOption::None => true,
|
|
|
+ GOption::Some(_) => false,
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn manual_drop(&self) {
|
|
|
+ *self.content.blocking_write() = GOption::None;
|
|
|
}
|
|
|
|
|
|
pub async fn get(&self) -> RwLockReadGuard<GOption<T>> {
|
|
@@ -115,3 +127,10 @@ impl<T> AsyncGlobalContainer<T> {
|
|
|
self.content.blocking_write()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+#[cfg(feature = "tokio")]
|
|
|
+impl<T> Drop for AsyncGlobalContainer<T> {
|
|
|
+ fn drop(&mut self) {
|
|
|
+ self.manual_drop();
|
|
|
+ }
|
|
|
+}
|