runAsync static method

Future<void> runAsync(
  1. Future<void> action(), {
  2. String? name,
  3. ErrorCallback? onError,
})

Implementation

static Future<void> runAsync(
  /// Function method.
  Future<void> Function() action, {
  String? name,
  ErrorCallback? onError,
}) async {
  /// Stores the =.
  final actionName =
      name ?? _getCachedAsyncActionName(_actionStack.length + 1);

  /// Stores the =.
  final wasInAction = _isInAction;

  /// if method.
  if (!wasInAction) {
    _isInAction = true;
  }

  _actionStack.add(actionName);

  try {
    await MinixErrorHandler.safeExecuteAsync(
      action,
      onError: onError ?? _defaultErrorHandler,
      context: 'Async Action: $actionName',
    );
  } finally {
    _actionStack.removeLast();

    /// if method.
    if (!wasInAction) {
      _isInAction = false;
      _flushQueueOptimized();
    }
  }
}