tryLock method

  1. @useResult
Future<bool> tryLock(
  1. Duration timeout,
  2. FutureOr<void> action()
)

Implementation

@useResult
Future<bool> tryLock(
    Duration timeout, FutureOr<void> Function() action) async {
  final isSuccess = await tryAcquire(timeout);
  if (isSuccess) {
    try {
      await action();
    } finally {
      await release();
    }
  }

  return isSuccess;
}