protectRead method
Convenience method for protecting a function with a read lock.
A read lock is acquired before invoking the criticalSection
function.
If the critical section returns a Future, it waits for it to be completed
before the read lock is released. The read lock is always released
(even if the critical section throws an exception).
Returns a Future that completes after the read lock is released.
Implementation
Future<void> protectRead(Function criticalSection) async {
await acquireRead();
try {
await criticalSection();
} finally {
release();
}
}