submit<T> method

Future<T> submit<T>(
  1. Future<T> task()
)

Implementation

Future<T> submit<T>(Future<T> Function() task) async {
  final completer = Completer<T>();

  _count.update((v) => v + 1);

  _queue.add(
    () => completer.completeWith(task),
  );

  try {
    return await completer.future;
  } finally {
    _count.update((v) => v - 1);
  }
}