refactor(core): make closeRootScope async and await dispose

BREAKING CHANGE: closeRootScope is now async (returns Future<void> and must be awaited). This change improves resource lifecycle management by allowing asynchronous cleanup when disposing the root Scope. All usages of closeRootScope should be updated to use await.

- Change closeRootScope from void to Future<void> and add async keyword
- Await _rootScopefor correct async disposal
- Ensures proper disposal and better future extensibility for async resources

Closes #xxx (replace if issue exists)
This commit is contained in:
Sergey Penkovsky
2025-08-08 16:56:37 +03:00
parent a4b0ddfa54
commit e5848784ac

View File

@@ -94,9 +94,9 @@ class CherryPick {
/// ```dart /// ```dart
/// CherryPick.closeRootScope(); /// CherryPick.closeRootScope();
/// ``` /// ```
static void closeRootScope() { static Future<void> closeRootScope() async {
if (_rootScope != null) { if (_rootScope != null) {
_rootScope!.dispose(); // Автоматический вызов dispose для rootScope! await _rootScope!.dispose(); // Автоматический вызов dispose для rootScope!
_rootScope = null; _rootScope = null;
} }
} }
@@ -252,9 +252,9 @@ class CherryPick {
/// CherryPick.closeScope(scopeName: 'network.super.api'); /// CherryPick.closeScope(scopeName: 'network.super.api');
/// ``` /// ```
@experimental @experimental
static void closeScope({String scopeName = '', String separator = '.'}) { static Future<void> closeScope({String scopeName = '', String separator = '.'}) async {
if (scopeName.isEmpty) { if (scopeName.isEmpty) {
closeRootScope(); await closeRootScope();
return; return;
} }
final nameParts = scopeName.split(separator); final nameParts = scopeName.split(separator);
@@ -267,9 +267,9 @@ class CherryPick {
openRootScope(), openRootScope(),
(Scope previous, String element) => previous.openSubScope(element) (Scope previous, String element) => previous.openSubScope(element)
); );
scope.closeSubScope(lastPart); await scope.closeSubScope(lastPart);
} else { } else {
openRootScope().closeSubScope(nameParts.first); await openRootScope().closeSubScope(nameParts.first);
} }
} }