method ClusterApi.lockFenced
Like lock; the body receives the fencing token of this holding: it increases with every acquisition of the lock, so a resource
that remembers the highest token it saw can refuse a holder that was paused and lost the lock meanwhile.
Example:
fn main() io, net, time {
let r = cluster.lockFenced("report") { fence => fence.valid() }
match r {
bool ok => print("fence valid: {ok}")
LockTimeout _ => print("busy")
NetError _ => print("unavailable")
}
}Output
fence valid: true
pub(api) fn lockFenced<T, effect F>(key: str, ttl: Duration = 30s, wait: Duration = 60s, body: fn(Fence) -> T F) -> T | LockTimeout | NetError net, time, FSince. 1.0.0-beta
Parameters
Returns
T
Errors
LockTimeoutNetError net, time, F- `LockTimeout` when the lock is not free within `wait`; `NetError` when the lock service cannot be reached.
Effects
none declared (pure unless the body says otherwise)
Defined in: std/core/node.oxl:443