Skip to content

Commit f608a00

Browse files
authored
Format packages to new style (#883)
1 parent 804ff11 commit f608a00

File tree

186 files changed

+8103
-4615
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+8103
-4615
lines changed

pkgs/async/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 2.13.1-wip
22

33
- Fix `StreamGroup.broadcast().close()` to properly complete when all streams in the group close without being explicitly removed.
4+
- Run `dart format` with the new style.
45

56
## 2.13.0
67

pkgs/async/lib/src/async_cache.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@ class AsyncCache<T> {
8585
throw StateError('Previously used to cache via `fetch`');
8686
}
8787
var splitter = _cachedStreamSplitter ??= StreamSplitter(
88-
callback().transform(StreamTransformer.fromHandlers(handleDone: (sink) {
89-
_startStaleTimer();
90-
sink.close();
91-
})));
88+
callback().transform(
89+
StreamTransformer.fromHandlers(
90+
handleDone: (sink) {
91+
_startStaleTimer();
92+
sink.close();
93+
},
94+
),
95+
),
96+
);
9297
return splitter.split();
9398
}
9499

pkgs/async/lib/src/byte_collector.dart

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,33 @@ Future<Uint8List> collectBytes(Stream<List<int>> source) {
2828
/// If any of the input data are not valid bytes, they will be truncated to
2929
/// an eight-bit unsigned value in the resulting list.
3030
CancelableOperation<Uint8List> collectBytesCancelable(
31-
Stream<List<int>> source) {
31+
Stream<List<int>> source,
32+
) {
3233
return _collectBytes(
33-
source,
34-
(subscription, result) => CancelableOperation.fromFuture(result,
35-
onCancel: subscription.cancel));
34+
source,
35+
(subscription, result) =>
36+
CancelableOperation.fromFuture(result, onCancel: subscription.cancel),
37+
);
3638
}
3739

3840
/// Generalization over [collectBytes] and [collectBytesCancelable].
3941
///
4042
/// Performs all the same operations, but the final result is created
4143
/// by the [result] function, which has access to the stream subscription
4244
/// so it can cancel the operation.
43-
T _collectBytes<T>(Stream<List<int>> source,
44-
T Function(StreamSubscription<List<int>>, Future<Uint8List>) result) {
45+
T _collectBytes<T>(
46+
Stream<List<int>> source,
47+
T Function(StreamSubscription<List<int>>, Future<Uint8List>) result,
48+
) {
4549
var bytes = BytesBuilder(copy: false);
4650
var completer = Completer<Uint8List>.sync();
47-
var subscription =
48-
source.listen(bytes.add, onError: completer.completeError, onDone: () {
49-
completer.complete(bytes.takeBytes());
50-
}, cancelOnError: true);
51+
var subscription = source.listen(
52+
bytes.add,
53+
onError: completer.completeError,
54+
onDone: () {
55+
completer.complete(bytes.takeBytes());
56+
},
57+
cancelOnError: true,
58+
);
5159
return result(subscription, completer.future);
5260
}

pkgs/async/lib/src/cancelable_operation.dart

Lines changed: 116 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ class CancelableOperation<T> {
2929
///
3030
/// Calling this constructor is equivalent to creating a
3131
/// [CancelableCompleter] and completing it with [result].
32-
factory CancelableOperation.fromFuture(Future<T> result,
33-
{FutureOr Function()? onCancel}) =>
32+
factory CancelableOperation.fromFuture(
33+
Future<T> result, {
34+
FutureOr Function()? onCancel,
35+
}) =>
3436
(CancelableCompleter<T>(onCancel: onCancel)..complete(result)).operation;
3537

3638
/// Creates a [CancelableOperation] which completes to [value].
@@ -51,7 +53,8 @@ class CancelableOperation<T> {
5153
/// subscription will be canceled (unlike
5254
/// `CancelableOperation.fromFuture(subscription.asFuture())`).
5355
static CancelableOperation<void> fromSubscription(
54-
StreamSubscription<void> subscription) {
56+
StreamSubscription<void> subscription,
57+
) {
5558
var completer = CancelableCompleter<void>(onCancel: subscription.cancel);
5659
subscription.onDone(completer.complete);
5760
subscription.onError((Object error, StackTrace stackTrace) {
@@ -70,7 +73,8 @@ class CancelableOperation<T> {
7073
/// new operation is cancelled, all the [operations] are cancelled as
7174
/// well.
7275
static CancelableOperation<T> race<T>(
73-
Iterable<CancelableOperation<T>> operations) {
76+
Iterable<CancelableOperation<T>> operations,
77+
) {
7478
operations = operations.toList();
7579
if (operations.isEmpty) {
7680
throw ArgumentError('May not be empty', 'operations');
@@ -83,20 +87,25 @@ class CancelableOperation<T> {
8387
done = true;
8488
return Future.wait([
8589
for (var operation in operations)
86-
if (!operation.isCanceled) operation.cancel()
90+
if (!operation.isCanceled) operation.cancel(),
8791
]);
8892
}
8993

9094
var completer = CancelableCompleter<T>(onCancel: cancelAll);
9195
for (var operation in operations) {
92-
operation.then((value) {
93-
if (!done) cancelAll().whenComplete(() => completer.complete(value));
94-
}, onError: (error, stackTrace) {
95-
if (!done) {
96-
cancelAll()
97-
.whenComplete(() => completer.completeError(error, stackTrace));
98-
}
99-
}, propagateCancel: false);
96+
operation.then(
97+
(value) {
98+
if (!done) cancelAll().whenComplete(() => completer.complete(value));
99+
},
100+
onError: (error, stackTrace) {
101+
if (!done) {
102+
cancelAll().whenComplete(
103+
() => completer.completeError(error, stackTrace),
104+
);
105+
}
106+
},
107+
propagateCancel: false,
108+
);
100109
}
101110

102111
return completer.operation;
@@ -114,16 +123,21 @@ class CancelableOperation<T> {
114123
/// This is like `value.asStream()`, but if a subscription to the stream is
115124
/// canceled, this operation is as well.
116125
Stream<T> asStream() {
117-
var controller =
118-
StreamController<T>(sync: true, onCancel: _completer._cancel);
119-
120-
_completer._inner?.future.then((value) {
121-
controller.add(value);
122-
controller.close();
123-
}, onError: (Object error, StackTrace stackTrace) {
124-
controller.addError(error, stackTrace);
125-
controller.close();
126-
});
126+
var controller = StreamController<T>(
127+
sync: true,
128+
onCancel: _completer._cancel,
129+
);
130+
131+
_completer._inner?.future.then(
132+
(value) {
133+
controller.add(value);
134+
controller.close();
135+
},
136+
onError: (Object error, StackTrace stackTrace) {
137+
controller.addError(error, stackTrace);
138+
controller.close();
139+
},
140+
);
127141
return controller.stream;
128142
}
129143

@@ -172,24 +186,28 @@ class CancelableOperation<T> {
172186
/// operation is canceled as well. Pass `false` if there are multiple
173187
/// listeners on this operation and canceling the [onValue], [onError], and
174188
/// [onCancel] callbacks should not cancel the other listeners.
175-
CancelableOperation<R> then<R>(FutureOr<R> Function(T) onValue,
176-
{FutureOr<R> Function(Object, StackTrace)? onError,
177-
FutureOr<R> Function()? onCancel,
178-
bool propagateCancel = true}) =>
179-
thenOperation<R>((value, completer) {
180-
completer.complete(onValue(value));
181-
},
182-
onError: onError == null
183-
? null
184-
: (error, stackTrace, completer) {
185-
completer.complete(onError(error, stackTrace));
186-
},
187-
onCancel: onCancel == null
188-
? null
189-
: (completer) {
190-
completer.complete(onCancel());
191-
},
192-
propagateCancel: propagateCancel);
189+
CancelableOperation<R> then<R>(
190+
FutureOr<R> Function(T) onValue, {
191+
FutureOr<R> Function(Object, StackTrace)? onError,
192+
FutureOr<R> Function()? onCancel,
193+
bool propagateCancel = true,
194+
}) =>
195+
thenOperation<R>(
196+
(value, completer) {
197+
completer.complete(onValue(value));
198+
},
199+
onError: onError == null
200+
? null
201+
: (error, stackTrace, completer) {
202+
completer.complete(onError(error, stackTrace));
203+
},
204+
onCancel: onCancel == null
205+
? null
206+
: (completer) {
207+
completer.complete(onCancel());
208+
},
209+
propagateCancel: propagateCancel,
210+
);
193211

194212
/// Creates a new cancelable operation to be completed when this operation
195213
/// completes normally or as an error, or is cancelled.
@@ -222,13 +240,15 @@ class CancelableOperation<T> {
222240
/// listeners on this operation and canceling the [onValue], [onError], and
223241
/// [onCancel] callbacks should not cancel the other listeners.
224242
CancelableOperation<R> thenOperation<R>(
225-
FutureOr<void> Function(T, CancelableCompleter<R>) onValue,
226-
{FutureOr<void> Function(Object, StackTrace, CancelableCompleter<R>)?
227-
onError,
228-
FutureOr<void> Function(CancelableCompleter<R>)? onCancel,
229-
bool propagateCancel = true}) {
243+
FutureOr<void> Function(T, CancelableCompleter<R>) onValue, {
244+
FutureOr<void> Function(Object, StackTrace, CancelableCompleter<R>)?
245+
onError,
246+
FutureOr<void> Function(CancelableCompleter<R>)? onCancel,
247+
bool propagateCancel = true,
248+
}) {
230249
final completer = CancelableCompleter<R>(
231-
onCancel: propagateCancel ? _cancelIfNotCanceled : null);
250+
onCancel: propagateCancel ? _cancelIfNotCanceled : null,
251+
);
232252

233253
// if `_completer._inner` completes before `completer` is cancelled
234254
// call `onValue` or `onError` with the result, and complete `completer`
@@ -246,25 +266,29 @@ class CancelableOperation<T> {
246266
// completes before `completer` is cancelled,
247267
// then cancel `cancelCompleter`. (Cancelling twice is safe.)
248268

249-
_completer._inner?.future.then<void>((value) async {
250-
if (completer.isCanceled) return;
251-
try {
252-
await onValue(value, completer);
253-
} catch (error, stack) {
254-
completer.completeError(error, stack);
255-
}
256-
},
257-
onError: onError == null
258-
? completer.completeError // Is ignored if already cancelled.
259-
: (Object error, StackTrace stack) async {
260-
if (completer.isCanceled) return;
261-
try {
262-
await onError(error, stack, completer);
263-
} catch (error2, stack2) {
264-
completer.completeErrorIfPending(
265-
error2, identical(error, error2) ? stack : stack2);
266-
}
267-
});
269+
_completer._inner?.future.then<void>(
270+
(value) async {
271+
if (completer.isCanceled) return;
272+
try {
273+
await onValue(value, completer);
274+
} catch (error, stack) {
275+
completer.completeError(error, stack);
276+
}
277+
},
278+
onError: onError == null
279+
? completer.completeError // Is ignored if already cancelled.
280+
: (Object error, StackTrace stack) async {
281+
if (completer.isCanceled) return;
282+
try {
283+
await onError(error, stack, completer);
284+
} catch (error2, stack2) {
285+
completer.completeErrorIfPending(
286+
error2,
287+
identical(error, error2) ? stack : stack2,
288+
);
289+
}
290+
},
291+
);
268292
final cancelForwarder = _CancelForwarder<R>(completer, onCancel);
269293
if (_completer.isCanceled) {
270294
cancelForwarder._forward();
@@ -430,11 +454,14 @@ class CancelableCompleter<T> {
430454
return;
431455
}
432456

433-
value.then((result) {
434-
_completeNow()?.complete(result);
435-
}, onError: (Object error, StackTrace stackTrace) {
436-
_completeNow()?.completeError(error, stackTrace);
437-
});
457+
value.then(
458+
(result) {
459+
_completeNow()?.complete(result);
460+
},
461+
onError: (Object error, StackTrace stackTrace) {
462+
_completeNow()?.completeError(error, stackTrace);
463+
},
464+
);
438465
}
439466

440467
/// Makes this [CancelableCompleter.operation] complete with the same result
@@ -443,23 +470,30 @@ class CancelableCompleter<T> {
443470
/// If [propagateCancel] is `true` (the default), and the [operation] of this
444471
/// completer is canceled before [result] completes, then [result] is also
445472
/// canceled.
446-
void completeOperation(CancelableOperation<T> result,
447-
{bool propagateCancel = true}) {
473+
void completeOperation(
474+
CancelableOperation<T> result, {
475+
bool propagateCancel = true,
476+
}) {
448477
if (!_mayComplete) throw StateError('Already completed');
449478
_mayComplete = false;
450479
if (isCanceled) {
451480
if (propagateCancel) result.cancel();
452481
result.value.ignore();
453482
return;
454483
}
455-
result.then<void>((value) {
456-
_inner?.complete(
457-
value); // _inner is set to null if this.operation is cancelled.
458-
}, onError: (error, stack) {
459-
_inner?.completeError(error, stack);
460-
}, onCancel: () {
461-
operation.cancel();
462-
});
484+
result.then<void>(
485+
(value) {
486+
_inner?.complete(
487+
value,
488+
); // _inner is set to null if this.operation is cancelled.
489+
},
490+
onError: (error, stack) {
491+
_inner?.completeError(error, stack);
492+
},
493+
onCancel: () {
494+
operation.cancel();
495+
},
496+
);
463497
if (propagateCancel) {
464498
_cancelCompleter?.future.whenComplete(result.cancel);
465499
}
@@ -519,7 +553,7 @@ class CancelableCompleter<T> {
519553
final isFuture = toReturn is Future;
520554
final cancelFutures = <Future<Object?>>[
521555
if (isFuture) toReturn,
522-
...?_cancelForwarders?.map(_forward).nonNulls
556+
...?_cancelForwarders?.map(_forward).nonNulls,
523557
];
524558
final results = (isFuture && cancelFutures.length == 1)
525559
? [await toReturn]

pkgs/async/lib/src/chunked_stream_reader.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ class ChunkedStreamReader<T> {
140140
List<T> output;
141141
if (_buffer is Uint8List) {
142142
output = Uint8List.sublistView(
143-
_buffer as Uint8List, _offset, _offset + size) as List<T>;
143+
_buffer as Uint8List,
144+
_offset,
145+
_offset + size,
146+
) as List<T>;
144147
} else {
145148
output = _buffer.sublist(_offset, _offset + size);
146149
}

pkgs/async/lib/src/delegate/event_sink.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class DelegatingEventSink<T> implements EventSink<T> {
2323
/// [add] may throw a [TypeError] if the argument type doesn't match the
2424
/// reified type of [sink].
2525
@Deprecated(
26-
'Use StreamController<T>(sync: true)..stream.cast<S>().pipe(sink)')
26+
'Use StreamController<T>(sync: true)..stream.cast<S>().pipe(sink)',
27+
)
2728
static EventSink<T> typed<T>(EventSink sink) =>
2829
sink is EventSink<T> ? sink : DelegatingEventSink._(sink);
2930

pkgs/async/lib/src/delegate/sink.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class DelegatingSink<T> implements Sink<T> {
2121
/// throw a [TypeError] if the argument type doesn't match the reified type of
2222
/// [sink].
2323
@Deprecated(
24-
'Use StreamController<T>(sync: true)..stream.cast<S>().pipe(sink)')
24+
'Use StreamController<T>(sync: true)..stream.cast<S>().pipe(sink)',
25+
)
2526
static Sink<T> typed<T>(Sink sink) =>
2627
sink is Sink<T> ? sink : DelegatingSink._(sink);
2728

0 commit comments

Comments
 (0)