MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / with_lock

Method with_lock

src/docker/proxy_manager.rs:56–77  ·  view source on GitHub ↗

Execute an operation while holding both in-process and cross-process locks for the given proxy fingerprint.

(&self, fingerprint: &str, operation: F)

Source from the content-addressed store, hash-verified

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<()>> {

Callers 2

acquire_proxyMethod · 0.80
release_proxyMethod · 0.80

Calls 3

lock_pathMethod · 0.80
acquire_flockFunction · 0.70
get_or_create_lockMethod · 0.45

Tested by

no test coverage detected