safe_executor library
A Dart package for safely executing asynchronous tasks.
This library provides a simple and type-safe way to handle async operations that may fail, using a Result type that encapsulates either success or failure.
Example usage:
import 'package:safe_executor/safe_executor.dart';
Future<void> main() async {
final result = await SafeExecutor.run(() async {
// Your async operation here
return await someAsyncOperation();
});
switch (result) {
case Success(value: final data):
print('Operation succeeded: $data');
case Failure(value: final error):
print('Operation failed: $error');
}
}
Classes
-
Failure<
S, F> -
Represents a failed result containing a value of type
F. -
Result<
S, F> - A sealed class representing the result of an operation that can either succeed or fail.
- SafeExecutor
- A utility class for safely executing asynchronous operations.
-
Success<
S, F> -
Represents a successful result containing a value of type
S.