run method
Run an async operation with automatic state management Returns null if the effect is disposed during execution
Implementation
Future<T?> run(Future<T> Function() operation) async {
if (_disposed) return null;
try {
// Set loading state first
loading();
// Check if disposed after setting loading state
if (_disposed) return null;
// Execute the operation
final result = await operation();
// Check if disposed after operation completes
if (_disposed) return null;
// Set success state with the result
success(result);
return result;
} catch (e) {
// Check if disposed before setting error
if (_disposed) return null;
// Set error state
setError(e);
// Re-throw the error so callers can handle it if needed
rethrow;
}
}