runLocked<TResult> method

Future<TResult> runLocked<TResult>(
  1. FutureOr<TResult> job()
)

Function job is executed immediately if the semaphore is not locked, as soon as the last scheduled job finishes otherwise.

Implementation

Future<TResult> runLocked<TResult>(FutureOr<TResult> Function() job) async {
  try {
    await lock();
    return await job();
  } finally {
    release();
  }
}