run<T> method

Future<T> run<T>(
  1. Future<T> action()
)

Implementation

Future<T> run<T>(Future<T> Function() action) async {
  if (_active >= limit) {
    final waiter = Completer<void>();
    _queue.add(waiter);
    await waiter.future;
  }
  _active++;
  try {
    return await action();
  } finally {
    _active--;
    if (_queue.isNotEmpty) _queue.removeAt(0).complete();
  }
}