withDb

open suspend override fun <T> withDb(block: suspend (MeshtasticDatabase) -> T): T?(source)

Executes block once against the admitted current DB instance, bounding the caller's wait at withDbTimeoutMillis.

A callback is never replayed after it starts: an arbitrary block can perform one side effect and then fail, so transparently invoking it again against another pool could duplicate or split a logical write. A block abandoned after its deadline may reopen the active database for future calls, but the original failure is still propagated.

Containment is per pool, not process-wide: the callback runs on the pool's containment lane (poolLanes) in a manager-scoped child coroutine that owns the writer registration and releases it in its own finally. Only the wait is bounded — a started block still runs to completion under NonCancellable, so a bounded DB-critical section is never torn apart mid-write. A block that never returns (Room 3.x logs and retries connection-pool acquisition instead of throwing, so a leaked permit hangs forever) is abandoned rather than cancelled: the caller fails with DatabaseOperationTimeoutException and the active pool is reopened, so later calls are admitted against the replacement pool and its fresh lane instead of queueing behind the wedge. A block still holding the database's write lock is slow rather than wedged, so its pool is kept and later calls wait for the lock.

Long-lived Flow/Paging reads must stay out of withDb; see observeCurrentDb and withReadDb.