method ClusterApi.lock
cluster.lock(key, ttl: LOCK_TTL) { … } (§12.6): runs body while this node holds the distributed lock key; waits for the
lock up to wait (default 60 s), then LockTimeout. The lease is renewed while the body runs. The lock may be lost (the
node was cut off for longer than ttl); use lockFenced and check the fencing token at the protected resource.
Example:
fn main() io, net, time {
let r = cluster.lock("report") { 42 }
match r {
i64 v => print("got {v}")
LockTimeout _ => print("busy")
NetError _ => print("unavailable")
}
}Вывод
got 42
pub(api) fn lock<T, effect F>(key: str, ttl: Duration = 30s, wait: Duration = 60s, body: fn() -> T F) -> T | LockTimeout | NetError net, time, FС версии. 1.0.0-beta
Параметры
Возвращает
T
Ошибки
LockTimeoutNetError net, time, F- `LockTimeout` when the lock is not free within `wait`; `NetError` when the lock service cannot be reached.
Эффекты
не объявлены (чистая, пока тело не говорит иное)
Определено в: std/core/node.oxl:416