tryWithLock

inline fun <T> Mutex.tryWithLock(block: () -> T): T?

Runs block while holding this mutex only if the mutex is free, returning null otherwise.

The lock attempt uses Mutex.tryLock, so this function never waits and null means the mutex was held by someone else. The mutex is released even when block throws.

Cancellation: this function does not suspend and performs no cancellation checks; a non-suspending block runs to completion once started.