run<T> method

Future<R> run<T>(
  1. ARunnable<T, R> runnable,
  2. [T param]
)

Implementation

Future<R> run<T>(ARunnable<T, R> runnable, [T param]) async {
  final completer = Completer<R>();
  if (_completerList.isNotEmpty) {
    _completerList.add(completer);
    return completer.future;
  } else {
    _completerList.add(completer);
  }

  try {
    final result = await runnable(param);
    _completerList.forEach((element) {
      element.complete(result);
    });
    _completerList.clear();
  } catch (e) {
    _completerList.forEach((element) {
      element.completeError(e);
    });
    _completerList.clear();
  }
  return completer.future;
}