浏览代码

Rename `still_active` to `stale`

Cesar Rodas 2 月之前
父节点
当前提交
fb4c470a9a
共有 2 个文件被更改,包括 12 次插入9 次删除
  1. 11 8
      crates/cdk-sql-common/src/pool.rs
  2. 1 1
      crates/cdk-sqlite/src/common.rs

+ 11 - 8
crates/cdk-sql-common/src/pool.rs

@@ -35,10 +35,13 @@ pub trait ResourceManager: Debug {
     /// The error the resource may return when creating a new instance
     type Error: Debug;
 
-    /// Creates a new resource with a given config
+    /// Creates a new resource with a given config.
+    ///
+    /// If `stale` is every set to TRUE it is assumed the resource is no longer valid and it will be
+    /// dropped.
     fn new_resource(
         config: &Self::Config,
-        still_valid: Arc<AtomicBool>,
+        stale: Arc<AtomicBool>,
         timeout: Duration,
     ) -> Result<Self::Resource, Error<Self::Error>>;
 
@@ -139,13 +142,13 @@ where
         let mut resources = self.queue.lock().map_err(|_| Error::Poison)?;
 
         loop {
-            if let Some(resource) = resources.pop() {
-                if resource.0.load(Ordering::SeqCst) {
+            if let Some((stale, resource)) = resources.pop() {
+                if !stale.load(Ordering::SeqCst) {
                     drop(resources);
                     self.in_use.fetch_add(1, Ordering::AcqRel);
 
                     return Ok(PooledResource {
-                        resource: Some(resource),
+                        resource: Some((stale, resource)),
                         pool: self.clone(),
                     });
                 }
@@ -154,12 +157,12 @@ where
             if self.in_use.load(Ordering::Relaxed) < self.max_size {
                 drop(resources);
                 self.in_use.fetch_add(1, Ordering::AcqRel);
-                let still_valid: Arc<AtomicBool> = Arc::new(true.into());
+                let stale: Arc<AtomicBool> = Arc::new(false.into());
 
                 return Ok(PooledResource {
                     resource: Some((
-                        still_valid.clone(),
-                        RM::new_resource(&self.config, still_valid, timeout)?,
+                        stale.clone(),
+                        RM::new_resource(&self.config, stale, timeout)?,
                     )),
                     pool: self.clone(),
                 });

+ 1 - 1
crates/cdk-sqlite/src/common.rs

@@ -26,7 +26,7 @@ impl ResourceManager for SqliteConnectionManager {
 
     fn new_resource(
         config: &Self::Config,
-        _still_valid: Arc<AtomicBool>,
+        _stale: Arc<AtomicBool>,
         _timeout: Duration,
     ) -> Result<Self::Resource, pool::Error<Self::Error>> {
         let conn = if let Some(path) = config.path.as_ref() {