Skip to main content

update

Function update 

Source
pub fn update<T>(
    f: impl FnOnce(&mut Value) -> T,
) -> Result<(T, Option<String>), String>
Expand description

Read, change and write the state under an exclusive lock.

Two runners (two unv exec --pool, the app beside the CLI) each did load(), picked a member, record_use and save(): the second save erased the first’s cursor move and use count, so two callers were handed the same key and a cooldown set by one was lost, handing a just-rate-limited key out again. Holding the lock from the read to the rename makes each runner see the previous one’s result. Returns the closure’s value and, if the write failed, why.