Execute an operation while holding both in-process and cross-process locks for the given proxy fingerprint.
(&self, fingerprint: &str, operation: F)
| 54 | /// Execute an operation while holding both in-process and cross-process locks |
| 55 | /// for the given proxy fingerprint. |
| 56 | async fn with_lock<F, Fut, T>(&self, fingerprint: &str, operation: F) -> T |
| 57 | where |
| 58 | F: FnOnce() -> Fut, |
| 59 | Fut: std::future::Future<Output = T>, |
| 60 | { |
| 61 | let lock = self.get_or_create_lock(fingerprint).await; |
| 62 | let _guard = lock.lock().await; |
| 63 | |
| 64 | let lock_path = self.lock_path(fingerprint); |
| 65 | if let Some(parent) = lock_path.parent() { |
| 66 | let _ = std::fs::create_dir_all(parent); |
| 67 | } |
| 68 | let _flock_file = acquire_flock(lock_path.clone()).await.unwrap_or_else(|e| { |
| 69 | panic!( |
| 70 | "Failed to acquire proxy file lock at {}: {}", |
| 71 | lock_path.display(), |
| 72 | e |
| 73 | ) |
| 74 | }); |
| 75 | |
| 76 | operation().await |
| 77 | } |
| 78 | |
| 79 | /// Get or create an in-process lock for a proxy fingerprint. |
| 80 | async fn get_or_create_lock(&self, fingerprint: &str) -> Arc<Mutex<()>> { |
no test coverage detected