runLocked<R> method

R runLocked<R>(
  1. R action()
)

Run the given synchronous action under a mutex.

This function takes exclusive ownership of the mutex, executes action and then releases the mutex. It returns the value returned by action.

Warning: you can't combine runLocked with an asynchronous code.

Implementation

R runLocked<R>(R Function() action) {
  _lock();
  try {
    return action();
  } finally {
    _unlock();
  }
}