Ensure you have exclusive access in concurrent code
Only guaranteed if no one else has reference to the inner object
It can take a second type parameter to specify interface with write methods
This is public so inner object can be accessed directly ONLY SAFE in sync context
Acquire a read (shared) lock and call fn with the value. Release the lock when fn returns or throws.
Acquire a write (exclusive) lock and call fn with the value. Release the lock when fn returns or throws.
fn takes a setter function as second parameter, which you can use to update the value like x = set(newX)
x = set(newX)
Ensure you have exclusive access in concurrent code
Only guaranteed if no one else has reference to the inner object
It can take a second type parameter to specify interface with write methods