DbLock.wait.loop: def of mylsm-lsm-store@0.6.0.1 Import: import mylsm-lsm-store@0.6.0.1/src/DbLock.bend as DbLock Lines 271-320 of mylsm-lsm-store@0.6.0.1/src/DbLock.bend: https://jend.leeeet.dev/read.txt?path=mylsm-lsm-store@0.6.0.1/src/DbLock.bend&start_line=271&end_line=320 import Base import mylsm-lsm-store@0.6.0.1/src/DurableError.bend as DurableError import mylsm-lsm-store@0.6.0.1/src/Fs.bend as Fs # Runs lock, clock, and sleep transitions with one decreasing structural fuel. def wait.loop(fuel: Nat, state: WaitState) -> IO(Result<&1, &1, DurableError.Error, Lock>): match fuel: case 0n: wait.exhausted(state) case 1n+rest: match state: case TryLock{file, started_us, timeout_ms, backoff_ms, operation, path}: do IO>: pair : File & Result<&1, &1, U32 & String, Unit> <- DbLock.try_lock(file) wait.loop(rest, LockAttempt{pair, started_us, timeout_ms, backoff_ms, operation, path}) case LockAttempt{pair, started_us, timeout_ms, backoff_ms, operation, path}: match pair: case (file, Done{Unit{}}): IO.pure(Result<&1, &1, DurableError.Error, Lock>, Done{Lock{file}}) case (file, Fail{error}): wait.loop(rest, wait.attempt.state(wait.attempt.decision(error), file, started_us, timeout_ms, backoff_ms, operation, path)) case ReadClock{file, started_us, timeout_ms, backoff_ms, operation, path, purpose}: do IO>: result : Result<&1, &1, U32 & String, Nat> <- Fs.clock_monotonic() wait.loop(rest, ClockSample{file, started_us, timeout_ms, backoff_ms, operation, path, purpose, result}) case ClockSample{file, +started_us, +timeout_ms, +backoff_ms, operation, path, purpose, result}: match result: case Fail{error}: wait.host_error(file, error, operation, path) case Done{now_us}: +elapsed_us = Nat.sub(now_us, started_us) +elapsed_ms = Nat.div(elapsed_us, 1000n) wait.loop(rest, wait.clock.decision(purpose, file, started_us, timeout_ms, backoff_ms, operation, path, elapsed_ms)) case Pause{file, started_us, timeout_ms, backoff_ms, operation, path, duration_ms}: do IO>: result : Result<&1, &1, U32 & String, Unit> <- Fs.sleep_ms(duration_ms) wait.loop(rest, PauseResult{file, started_us, timeout_ms, backoff_ms, operation, path, result}) case PauseResult{file, started_us, timeout_ms, backoff_ms, operation, path, result}: match result: case Fail{error}: wait.host_error(file, error, operation, path) case Done{Unit{}}: wait.loop(rest, ReadClock{file, started_us, timeout_ms, backoff_ms, operation, path, CheckDeadline{}}) case WaitFatal{file, error, operation, path}: lock_failed(file, error, operation, path) case WaitExpired{file, operation, path}: wait.timeout(file, operation, path) Uses (27): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=File https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO.bind https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=IO.pure https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.div https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.sub https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Pair https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Result https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Sigma https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Unit https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/DbLock.bend&name=DbLock.try_lock https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/DbLock.bend&name=Lock https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/DbLock.bend&name=WaitPurpose https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/DbLock.bend&name=WaitState https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/DbLock.bend&name=lock_failed https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/DbLock.bend&name=wait.attempt.decision https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/DbLock.bend&name=wait.attempt.state https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/DbLock.bend&name=wait.clock.decision https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/DbLock.bend&name=wait.exhausted https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/DbLock.bend&name=wait.host_error https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/DbLock.bend&name=wait.timeout https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/DurableError.bend&name=Error https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/Fs.bend&name=clock_monotonic https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/Fs.bend&name=sleep_ms