(filepath: &str, f: F)
| 23 | } |
| 24 | |
| 25 | pub async fn with_file_lock<F, Fut, T>(filepath: &str, f: F) -> T |
| 26 | where |
| 27 | F: FnOnce() -> Fut, |
| 28 | Fut: Future<Output = T>, |
| 29 | { |
| 30 | let lock = { |
| 31 | let locks = get_file_locks(); |
| 32 | let mut locks_guard = locks.lock().unwrap(); |
| 33 | locks_guard |
| 34 | .entry(filepath.to_string()) |
| 35 | .or_insert_with(|| Arc::new(Mutex::new(()))) |
| 36 | .clone() |
| 37 | }; |
| 38 | |
| 39 | let _guard = lock.lock().await; |
| 40 | f().await |
| 41 | } |
| 42 | |
| 43 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 44 | pub struct QuestionDef { |
no test coverage detected