run<T> method

Future<T> run<T>(
  1. AsyncAction<T> fn
)

Acquires a permit, runs fn, then releases; ensures release on exception.

Returns the result of fn.

Implementation

Future<T> run<T>(AsyncAction<T> fn) async {
  await acquire();
  try {
    return await fn();
  } finally {
    release();
  }
}