lock_until_finished

Function lock_until_finished 

Source
pub fn lock_until_finished<R: Any>(
    lock: &mut impl Lock,
    op: impl FnOnce() -> R + UnwindSafe,
) -> SimpleLockResult<R>
Expand description

Simple utility function for wrapping a closure with a lock.

This will handle panics safely as long as they are UnwindSafe. The panic will be caught, the lock will be unlocked, and then the panic is released. This assumes the operation provided is transactional and will handle its own clean-up.

ยงExample

let mut lock = default_lock("MyAppName")?;
let result = lock_until_finished(
    &mut lock,
    || {
        // do something needing a lock.
    }
);