mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-23 21:13:35 +00:00
feat: Add async dependency resolution and enhance example
- Implemented async provider methods `toProvideAsync` and `toProvideAsyncWithParams` in `Binding` class, allowing asynchronous initialization with dynamic parameters. - Added typedefs `AsyncProvider<T>` and `AsyncProviderWithParams<T>` for better type clarity with async operations. - Introduced async resolution methods `resolveAsync` and `tryResolveAsync` in `Scope` for resolving asynchronous dependencies. - Updated example in `main.dart` to demonstrate async dependency resolution capabilities. - Modified `FeatureModule` to utilize async providers for `DataRepository` and `DataBloc`. - Replaced synchronous resolution with `resolveAsync` where applicable. - Handled potential errors in dependency resolution with try-catch. - Removed unnecessary whitespace for cleaner code formatting.
This commit is contained in:
@@ -37,7 +37,8 @@ class FeatureModule extends Module {
|
||||
}
|
||||
}
|
||||
|
||||
void main() async {
|
||||
Future<void> main() async {
|
||||
try {
|
||||
final scope = openRootScope().installModules([
|
||||
AppModule(),
|
||||
]);
|
||||
@@ -52,13 +53,16 @@ void main() async {
|
||||
onError: (e) => print('Error: $e'), onDone: () => print('DONE'));
|
||||
|
||||
await dataBloc.fetchData();
|
||||
} catch (e) {
|
||||
print('Error resolving dependency: $e');
|
||||
}
|
||||
}
|
||||
|
||||
class DataBloc {
|
||||
final DataRepository _dataRepository;
|
||||
|
||||
Stream<String> get data => _dataController.stream;
|
||||
final StreamController<String> _dataController = StreamController.broadcast();
|
||||
Stream<String> get data => _dataController.stream;
|
||||
|
||||
DataBloc(this._dataRepository);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user