| 992 | } |
| 993 | |
| 994 | fn wait_for_database( |
| 995 | timeout: std::time::Duration, |
| 996 | mut open: impl FnMut() -> Result<Self, RepositoryError>, |
| 997 | ) -> Result<Self, RepositoryError> { |
| 998 | let start = std::time::Instant::now(); |
| 999 | loop { |
| 1000 | match open() { |
| 1001 | Err(RepositoryError::DatabaseBusy) if start.elapsed() < timeout => { |
| 1002 | std::thread::sleep( |
| 1003 | std::time::Duration::from_millis(10) |
| 1004 | .min(timeout.saturating_sub(start.elapsed())), |
| 1005 | ); |
| 1006 | } |
| 1007 | result => return result, |
| 1008 | } |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | /// Open for a workspace transaction, waiting for transient writers. |
| 1013 | /// |