Skip to content

Commit 9ac03a1

Browse files
committed
+chore: Upade dependencies
1 parent 54da189 commit 9ac03a1

9 files changed

Lines changed: 78 additions & 225 deletions

File tree

lib/src/list_mixins/cancel_list_mixin.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import 'dart:async' show FutureOr;
1414

15-
import 'package:df_type/df_type.dart' show SequentialController;
15+
import 'package:df_type/df_type.dart' show OperationWaiter;
1616
import 'package:flutter/foundation.dart' show protected;
1717

1818
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
@@ -28,14 +28,10 @@ mixin CancelListsMixin {
2828

2929
@protected
3030
FutureOr<void> cancelAll() {
31-
final sc = SequentialController<void>();
31+
final operations = OperationWaiter<void>();
3232
for (final resource in _cancelList) {
33-
try {
34-
sc.add((_) => resource.cancel());
35-
} on NoSuchMethodError catch (e) {
36-
sc.addException(e);
37-
}
33+
operations.add(() => resource.cancel());
3834
}
39-
return sc.complete();
35+
return operations.wait();
4036
}
4137
}

lib/src/list_mixins/close_list_mixin.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import 'dart:async' show FutureOr;
1414

15-
import 'package:df_type/df_type.dart' show SequentialController;
15+
import 'package:df_type/df_type.dart' show OperationWaiter;
1616
import 'package:flutter/foundation.dart' show protected;
1717

1818
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
@@ -28,14 +28,10 @@ mixin CloseListsMixin {
2828

2929
@protected
3030
FutureOr<void> closeAll() {
31-
final sc = SequentialController<void>();
31+
final operations = OperationWaiter<void>();
3232
for (final resource in _closeList) {
33-
try {
34-
sc.add((_) => resource.close());
35-
} on NoSuchMethodError catch (e) {
36-
sc.addException(e);
37-
}
33+
operations.add(() => resource.close());
3834
}
39-
return sc.complete();
35+
return operations.wait();
4036
}
4137
}

lib/src/list_mixins/dispose_list_mixin.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import 'dart:async' show FutureOr;
1414

15-
import 'package:df_type/df_type.dart' show SequentialController;
15+
import 'package:df_type/df_type.dart' show OperationWaiter;
1616
import 'package:flutter/foundation.dart' show protected;
1717

1818
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
@@ -28,14 +28,10 @@ mixin DisposeListsMixin {
2828

2929
@protected
3030
FutureOr<void> disposeAll() {
31-
final sc = SequentialController<void>();
31+
final operations = OperationWaiter<void>();
3232
for (final resource in _disposeList) {
33-
try {
34-
sc.add((_) => resource.dispose());
35-
} on NoSuchMethodError catch (e) {
36-
sc.addException(e);
37-
}
33+
operations.add(() => resource.dispose());
3834
}
39-
return sc.complete();
35+
return operations.wait();
4036
}
4137
}

lib/src/list_mixins/stop_list_mixin.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import 'dart:async' show FutureOr;
1414

15-
import 'package:df_type/df_type.dart' show SequentialController;
15+
import 'package:df_type/df_type.dart' show OperationWaiter;
1616
import 'package:flutter/foundation.dart' show protected;
1717

1818
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
@@ -28,14 +28,10 @@ mixin StopListsMixin {
2828

2929
@protected
3030
FutureOr<void> stopAll() {
31-
final sc = SequentialController<void>();
31+
final operations = OperationWaiter<void>();
3232
for (final resource in _stopList) {
33-
try {
34-
sc.add((_) => resource.stop());
35-
} on NoSuchMethodError catch (e) {
36-
sc.addException(e);
37-
}
33+
operations.add(() => resource.stop());
3834
}
39-
return sc.complete();
35+
return operations.wait();
4036
}
4137
}

lib/src/will_mixins/will_cancel/will_cancel_mixin.dart

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212

1313
import 'dart:async' show FutureOr;
1414

15-
import 'package:df_type/df_type.dart' show SequentialController;
16-
import 'package:flutter/foundation.dart'
17-
show kDebugMode, mustCallSuper, nonVirtual;
15+
import 'package:df_type/df_type.dart' show OperationWaiter;
16+
import 'package:flutter/foundation.dart' show kDebugMode, mustCallSuper, nonVirtual;
1817

1918
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2019

@@ -27,8 +26,7 @@ import 'package:flutter/foundation.dart'
2726
/// invoked on each resource wrapped with [willCancel].
2827
mixin WillCancelMixin on CancelMixin {
2928
/// The list of resources marked for cancel via [willCancel].
30-
Set<_ToCancelResource<dynamic>> get toCancelResources =>
31-
Set.unmodifiable(_toCancelResources);
29+
Set<_ToCancelResource<dynamic>> get toCancelResources => Set.unmodifiable(_toCancelResources);
3230

3331
final Set<_ToCancelResource<dynamic>> _toCancelResources = {};
3432

@@ -50,13 +48,11 @@ mixin WillCancelMixin on CancelMixin {
5048
_verifyCancelMethod(resource);
5149
final disposable = (
5250
resource: resource as dynamic,
53-
onBeforeCancel:
54-
onBeforeCancel != null ? (dynamic e) => onBeforeCancel(e as T) : null,
51+
onBeforeCancel: onBeforeCancel != null ? (dynamic e) => onBeforeCancel(e as T) : null,
5552
);
5653

5754
// Check for any duplicate resource.
58-
final duplicate =
59-
_toCancelResources.where((e) => e.resource == resource).firstOrNull;
55+
final duplicate = _toCancelResources.where((e) => e.resource == resource).firstOrNull;
6056

6157
if (duplicate != null) {
6258
if (kDebugMode) {
@@ -78,41 +74,15 @@ mixin WillCancelMixin on CancelMixin {
7874
@mustCallSuper
7975
@override
8076
FutureOr<void> cancel() {
81-
final sc = SequentialController<void>();
82-
83-
try {
84-
// Call the parent's cancel method.
85-
sc.add((_) => super.cancel());
86-
87-
for (final disposable in _toCancelResources) {
88-
final resource = disposable.resource;
89-
// Skip invalid resources.
90-
if (!hasValidCancelMethod(resource)) continue;
91-
92-
// Attempt to call onBeforeCancel, catching and copying any exceptions.
93-
Object? onBeforeCancelError;
94-
try {
95-
sc.add((_) => disposable.onBeforeCancel?.call(resource));
96-
} catch (e) {
97-
onBeforeCancelError = e;
98-
}
99-
100-
// Attempt to call cancel on the resource.
101-
sc.add((_) => resource.cancel());
102-
103-
// If successful, rethrow any exception from onBeforeCancel.
104-
if (onBeforeCancelError != null) {
105-
throw onBeforeCancelError;
106-
}
107-
}
108-
} catch (e) {
109-
// Collect exceptions to throw them all at the end, ensuring cancel gets
110-
// called on all resources.
111-
sc.addException(e);
77+
final waiter = OperationWaiter<void>();
78+
waiter.add(super.cancel);
79+
for (final disposable in _toCancelResources) {
80+
final resource = disposable.resource;
81+
if (!hasValidCancelMethod(resource)) continue;
82+
waiter.add(() => disposable.onBeforeCancel?.call(resource));
83+
waiter.add(() => resource.cancel());
11284
}
113-
114-
// Return a Future or complete synchronously.
115-
return sc.complete();
85+
return waiter.wait();
11686
}
11787

11888
/// Throws [NoCancelMethodDebugError] if [resource] does not have a `cancel`
@@ -167,8 +137,7 @@ final class WillAlreadyCancelDebugError<T> extends Error {
167137
WillAlreadyCancelDebugError(this.resource);
168138

169139
@override
170-
String toString() =>
171-
'[$WillAlreadyCancelDebugError] willCancel has already '
140+
String toString() => '[$WillAlreadyCancelDebugError] willCancel has already '
172141
'been called on the resource ${resource.hashCode} and of type $T.';
173142
}
174143

@@ -182,8 +151,7 @@ mixin CancelMixin {
182151

183152
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
184153

185-
typedef _ToCancelResource<T> =
186-
({T resource, _OnBeforeCallback<T>? onBeforeCancel});
154+
typedef _ToCancelResource<T> = ({T resource, _OnBeforeCallback<T>? onBeforeCancel});
187155

188156
typedef _FutureOrCallback<T> = FutureOr<void> Function();
189157
typedef _OnBeforeCallback<T> = FutureOr<void> Function(T resource);

lib/src/will_mixins/will_close/will_close_mixin.dart

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212

1313
import 'dart:async' show FutureOr;
1414

15-
import 'package:df_type/df_type.dart' show SequentialController;
16-
import 'package:flutter/foundation.dart'
17-
show kDebugMode, mustCallSuper, nonVirtual;
15+
import 'package:df_type/df_type.dart' show OperationWaiter;
16+
import 'package:flutter/foundation.dart' show kDebugMode, mustCallSuper, nonVirtual;
1817

1918
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2019

@@ -27,8 +26,7 @@ import 'package:flutter/foundation.dart'
2726
/// invoked on each resource wrapped with [willClose].
2827
mixin WillCloseMixin on CloseMixin {
2928
/// The list of resources marked for close via [willClose].
30-
Set<_ToCloseResource<dynamic>> get toCloseResources =>
31-
Set.unmodifiable(_toCloseResources);
29+
Set<_ToCloseResource<dynamic>> get toCloseResources => Set.unmodifiable(_toCloseResources);
3230

3331
final Set<_ToCloseResource<dynamic>> _toCloseResources = {};
3432

@@ -50,13 +48,11 @@ mixin WillCloseMixin on CloseMixin {
5048
_verifyCloseMethod(resource);
5149
final disposable = (
5250
resource: resource as dynamic,
53-
onBeforeClose:
54-
onBeforeClose != null ? (dynamic e) => onBeforeClose(e as T) : null,
51+
onBeforeClose: onBeforeClose != null ? (dynamic e) => onBeforeClose(e as T) : null,
5552
);
5653

5754
// Check for any duplicate resource.
58-
final duplicate =
59-
_toCloseResources.where((e) => e.resource == resource).firstOrNull;
55+
final duplicate = _toCloseResources.where((e) => e.resource == resource).firstOrNull;
6056

6157
if (duplicate != null) {
6258
if (kDebugMode) {
@@ -78,41 +74,15 @@ mixin WillCloseMixin on CloseMixin {
7874
@mustCallSuper
7975
@override
8076
FutureOr<void> close() {
81-
final sc = SequentialController<void>();
82-
83-
try {
84-
// Call the parent's close method.
85-
sc.add((_) => super.close());
86-
87-
for (final disposable in _toCloseResources) {
88-
final resource = disposable.resource;
89-
// Skip invalid resources.
90-
if (!hasValidCloseMethod(resource)) continue;
91-
92-
// Attempt to call onBeforeClose, catching and copying any exceptions.
93-
Object? onBeforeCloseError;
94-
try {
95-
sc.add((_) => disposable.onBeforeClose?.call(resource));
96-
} catch (e) {
97-
onBeforeCloseError = e;
98-
}
99-
100-
// Attempt to call close on the resource.
101-
sc.add((_) => resource.close());
102-
103-
// If successful, rethrow any exception from onBeforeClose.
104-
if (onBeforeCloseError != null) {
105-
throw onBeforeCloseError;
106-
}
107-
}
108-
} catch (e) {
109-
// Collect exceptions to throw them all at the end, ensuring close gets
110-
// called on all resources.
111-
sc.addException(e);
77+
final waiter = OperationWaiter<void>();
78+
waiter.add(super.close);
79+
for (final disposable in _toCloseResources) {
80+
final resource = disposable.resource;
81+
if (!hasValidCloseMethod(resource)) continue;
82+
waiter.add(() => disposable.onBeforeClose?.call(resource));
83+
waiter.add(() => resource.close());
11284
}
113-
114-
// Return a Future or complete synchronously.
115-
return sc.complete();
85+
return waiter.wait();
11686
}
11787

11888
/// Throws [NoCloseMethodDebugError] if [resource] does not have a `close`
@@ -167,8 +137,7 @@ final class WillAlreadyCloseDebugError<T> extends Error {
167137
WillAlreadyCloseDebugError(this.resource);
168138

169139
@override
170-
String toString() =>
171-
'[$WillAlreadyCloseDebugError] willClose has already '
140+
String toString() => '[$WillAlreadyCloseDebugError] willClose has already '
172141
'been called on the resource ${resource.hashCode} and of type $T.';
173142
}
174143

@@ -182,8 +151,7 @@ mixin CloseMixin {
182151

183152
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
184153

185-
typedef _ToCloseResource<T> =
186-
({T resource, _OnBeforeCallback<T>? onBeforeClose});
154+
typedef _ToCloseResource<T> = ({T resource, _OnBeforeCallback<T>? onBeforeClose});
187155

188156
typedef _FutureOrCallback<T> = FutureOr<void> Function();
189157
typedef _OnBeforeCallback<T> = FutureOr<void> Function(T resource);

0 commit comments

Comments
 (0)