MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / open_existing_wait

Method open_existing_wait

atomic-repository/src/redb_change_store/mod.rs:299–318  ·  view source on GitHub ↗

Open the store in an existing database file, waiting at most `timeout` for an incompatible process handle to close. Other errors return immediately. redb refuses any open while another process holds the database — short-lived writers (a recording agent turn, a gated daemon mutation) are given this grace instead of failing the open. The same policy [`crate::Repository::open_existing_wait`] applies

(
        path: P,
        timeout: std::time::Duration,
    )

Source from the content-addressed store, hash-verified

297 /// same policy [`crate::Repository::open_existing_wait`] applies to
298 /// repository opens.
299 pub fn open_existing_wait<P: AsRef<Path>>(
300 path: P,
301 timeout: std::time::Duration,
302 ) -> RedbStoreResult<Self> {
303 let start = std::time::Instant::now();
304 loop {
305 match Self::open_existing(path.as_ref()) {
306 Err(RedbStoreError::Database(db))
307 if matches!(db.as_ref(), redb::DatabaseError::DatabaseAlreadyOpen)
308 && start.elapsed() < timeout =>
309 {
310 std::thread::sleep(
311 std::time::Duration::from_millis(10)
312 .min(timeout.saturating_sub(start.elapsed())),
313 );
314 }
315 result => return result,
316 }
317 }
318 }
319
320 /// Use the store's tables in an already-open database, creating any that
321 /// are missing.

Callers

nothing calls this directly

Calls 1

as_refMethod · 0.80

Tested by

no test coverage detected