Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.

Commit e4d75c1

Browse files
authored
Revert "Various clean-ups and null-safety improvements. (#140)" (#152)
This reverts commit 05b9553. Since this has not been published or rolled through to the SDK or Flutter we will hold it back to reduce risk.
1 parent 8e32089 commit e4d75c1

File tree

8 files changed

+42
-46
lines changed

8 files changed

+42
-46
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
## 2.5.0-nullsafety.4-dev
2-
31
## 2.5.0-nullsafety.3
42

53
* Update SDK constraints to `>=2.12.0-0 <3.0.0` based on beta release

lib/src/async_cache.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class AsyncCache<T> {
4242
/// The [duration] starts counting after the Future returned by [fetch]
4343
/// completes, or after the Stream returned by [fetchStream] emits a done
4444
/// event.
45-
AsyncCache(Duration duration) : _duration = duration;
45+
AsyncCache(this._duration);
4646

4747
/// Creates a cache that invalidates after an in-flight request is complete.
4848
///

lib/src/result/result.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ abstract class Result<T> {
9999
static Future<List<Result<T>>> captureAll<T>(Iterable<FutureOr<T>> elements) {
100100
var results = <Result<T>?>[];
101101
var pending = 0;
102-
var completer = Completer<List<Result<T>>>();
102+
late Completer<List<Result<T>>> completer;
103103
for (var element in elements) {
104104
if (element is Future<T>) {
105105
var i = results.length;
@@ -116,8 +116,9 @@ abstract class Result<T> {
116116
}
117117
}
118118
if (pending == 0) {
119-
completer.complete(List.from(results));
119+
return Future.value(List.from(results));
120120
}
121+
completer = Completer<List<Result<T>>>();
121122
return completer.future;
122123
}
123124

lib/src/single_subscription_transformer.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ class SingleSubscriptionTransformer<S, T> extends StreamTransformerBase<S, T> {
1818

1919
@override
2020
Stream<T> bind(Stream<S> stream) {
21-
var controller = StreamController<T>(sync: true);
22-
var subscription = stream.listen((value) {
21+
late StreamSubscription<S> subscription;
22+
var controller =
23+
StreamController<T>(sync: true, onCancel: () => subscription.cancel());
24+
subscription = stream.listen((value) {
2325
// TODO(nweiz): When we release a new major version, get rid of the second
2426
// type parameter and avoid this conversion.
2527
try {
@@ -28,7 +30,6 @@ class SingleSubscriptionTransformer<S, T> extends StreamTransformerBase<S, T> {
2830
controller.addError(error, stackTrace);
2931
}
3032
}, onError: controller.addError, onDone: controller.close);
31-
controller.onCancel = subscription.cancel;
3233
return controller.stream;
3334
}
3435
}

lib/src/stream_group.dart

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import 'dart:async';
2929
class StreamGroup<T> implements Sink<Stream<T>> {
3030
/// The stream through which all events from streams in the group are emitted.
3131
Stream<T> get stream => _controller.stream;
32-
final StreamController<T> _controller;
32+
late StreamController<T> _controller;
3333

3434
/// Whether the group is closed, meaning that no more streams may be added.
3535
var _closed = false;
@@ -72,20 +72,19 @@ class StreamGroup<T> implements Sink<Stream<T>> {
7272
}
7373

7474
/// Creates a new stream group where [stream] is single-subscriber.
75-
StreamGroup() : _controller = StreamController<T>(sync: true) {
76-
_controller
77-
..onListen = _onListen
78-
..onPause = _onPause
79-
..onResume = _onResume
80-
..onCancel = _onCancel;
75+
StreamGroup() {
76+
_controller = StreamController<T>(
77+
onListen: _onListen,
78+
onPause: _onPause,
79+
onResume: _onResume,
80+
onCancel: _onCancel,
81+
sync: true);
8182
}
8283

8384
/// Creates a new stream group where [stream] is a broadcast stream.
84-
StreamGroup.broadcast()
85-
: _controller = StreamController<T>.broadcast(sync: true) {
86-
_controller
87-
..onListen = _onListen
88-
..onCancel = _onCancelBroadcast;
85+
StreamGroup.broadcast() {
86+
_controller = StreamController<T>.broadcast(
87+
onListen: _onListen, onCancel: _onCancelBroadcast, sync: true);
8988
}
9089

9190
/// Adds [stream] as a member of this group.

lib/src/stream_zip.dart

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class StreamZip<T> extends Stream<List<T>> {
2222
{Function? onError, void Function()? onDone, bool? cancelOnError}) {
2323
cancelOnError = identical(true, cancelOnError);
2424
var subscriptions = <StreamSubscription<T>>[];
25-
var controller = StreamController<List<T>>();
25+
late StreamController<List<T>> controller;
2626
late List<T?> current;
2727
var dataCount = 0;
2828

@@ -32,7 +32,7 @@ class StreamZip<T> extends Stream<List<T>> {
3232
dataCount++;
3333
if (dataCount == subscriptions.length) {
3434
var data = List<T>.from(current);
35-
current.fillRange(0, current.length, null);
35+
current = List<T?>.filled(subscriptions.length, null);
3636
dataCount = 0;
3737
for (var i = 0; i < subscriptions.length; i++) {
3838
if (i != index) subscriptions[i].resume();
@@ -87,26 +87,23 @@ class StreamZip<T> extends Stream<List<T>> {
8787

8888
current = List<T?>.filled(subscriptions.length, null);
8989

90-
controller
91-
..onPause = () {
92-
for (var i = 0; i < subscriptions.length; i++) {
93-
// This may pause some subscriptions more than once.
94-
// These will not be resumed by onResume below, but must wait for the
95-
// next round.
96-
subscriptions[i].pause();
97-
}
90+
controller = StreamController<List<T>>(onPause: () {
91+
for (var i = 0; i < subscriptions.length; i++) {
92+
// This may pause some subscriptions more than once.
93+
// These will not be resumed by onResume below, but must wait for the
94+
// next round.
95+
subscriptions[i].pause();
9896
}
99-
..onResume = () {
100-
for (var i = 0; i < subscriptions.length; i++) {
101-
subscriptions[i].resume();
102-
}
97+
}, onResume: () {
98+
for (var i = 0; i < subscriptions.length; i++) {
99+
subscriptions[i].resume();
103100
}
104-
..onCancel = () {
105-
for (var i = 0; i < subscriptions.length; i++) {
106-
// Canceling more than once is safe.
107-
subscriptions[i].cancel();
108-
}
109-
};
101+
}, onCancel: () {
102+
for (var i = 0; i < subscriptions.length; i++) {
103+
// Canceling more than once is safe.
104+
subscriptions[i].cancel();
105+
}
106+
});
110107

111108
if (subscriptions.isEmpty) {
112109
controller.close();

lib/src/subscription_stream.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class SubscriptionStream<T> extends Stream<T> {
3131
/// an error.
3232
SubscriptionStream(StreamSubscription<T> subscription)
3333
: _source = subscription {
34+
var source = _source!;
35+
source.pause();
3436
// Clear callbacks to avoid keeping them alive unnecessarily.
35-
subscription
36-
..pause()
37-
..onData(null)
38-
..onError(null)
39-
..onDone(null);
37+
source.onData(null);
38+
source.onError(null);
39+
source.onDone(null);
4040
}
4141

4242
@override

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: async
2-
version: 2.5.0-nullsafety.4-dev
2+
version: 2.5.0-nullsafety.3
33

44
description: Utility functions and classes related to the 'dart:async' library.
55
homepage: https://www.github.com/dart-lang/async

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy