run method

Future<T?> run()

Run the action.

Implementation

Future<T?> run() async {
  if (isExecuting.val) {
    return null; // Already executing
  }

  isExecuting.emit(true);
  error.emit(null);

  try {
    final value = await execute();
    result.emit(value);
    after?.call(value);
    return value;
  } catch (e, stack) {
    error.emit(e);
    onError?.call(e, stack);
    return null;
  } finally {
    isExecuting.emit(false);
  }
}