mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-23 21:13:35 +00:00
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:
@@ -94,9 +94,9 @@ class CherryPick {
|
||||
/// ```dart
|
||||
/// CherryPick.closeRootScope();
|
||||
/// ```
|
||||
static void closeRootScope() {
|
||||
static Future<void> closeRootScope() async {
|
||||
if (_rootScope != null) {
|
||||
_rootScope!.dispose(); // Автоматический вызов dispose для rootScope!
|
||||
await _rootScope!.dispose(); // Автоматический вызов dispose для rootScope!
|
||||
_rootScope = null;
|
||||
}
|
||||
}
|
||||
@@ -252,9 +252,9 @@ class CherryPick {
|
||||
/// CherryPick.closeScope(scopeName: 'network.super.api');
|
||||
/// ```
|
||||
@experimental
|
||||
static void closeScope({String scopeName = '', String separator = '.'}) {
|
||||
static Future<void> closeScope({String scopeName = '', String separator = '.'}) async {
|
||||
if (scopeName.isEmpty) {
|
||||
closeRootScope();
|
||||
await closeRootScope();
|
||||
return;
|
||||
}
|
||||
final nameParts = scopeName.split(separator);
|
||||
@@ -267,9 +267,9 @@ class CherryPick {
|
||||
openRootScope(),
|
||||
(Scope previous, String element) => previous.openSubScope(element)
|
||||
);
|
||||
scope.closeSubScope(lastPart);
|
||||
await scope.closeSubScope(lastPart);
|
||||
} else {
|
||||
openRootScope().closeSubScope(nameParts.first);
|
||||
await openRootScope().closeSubScope(nameParts.first);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user