def with_pidlock

cswap-bend-cli@0.1.0.0 · daemon/pidlock.bend:75

import cswap-bend-cli@0.1.0.0/daemon/pidlock.bend as Pidlock
import Base
import cswap-bend-cli@0.1.0.0/fs/write.bend as FsW
import cswap-bend-cli@0.1.0.0/act.bend as Act
import cswap-bend-cli@0.1.0.0/lock.bend as Lock

75# Run `act` as the one decider of this state dir. A second caller gets
76# Fail{(11, "Another `cswap auto` is already running ...")} and `act` never starts.
77def with_pidlock(-A: Type, +state_dir: String, act: Act.of(A)) -> Act.of(A):
78  do ActM<A>:
79    FsW.mkdir_p(state_dir)
80    m : Maybe<&1, File> <- Lock.acquire(lock_path(state_dir), 0)
81    held(A, state_dir, m, act)

Uses (11)

Used by (2)