lock method
Acquires the lock, then executes the callback function action, and
then releases the lock.
Parameters:
action: A callback function that will be executed after the lock is acquired.
Implementation
Future<void> lock(FutureOr<void> Function() action) async {
await acquire();
try {
await action();
} finally {
await release();
}
}