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

Commit 5a43734

Browse files
authored
Merge null_safety branch into master (#125)
Migrates this package to null safety and prepares for a null safety pre-release, once we have landed the package internally and in the SDK to verify its accuracy.
1 parent e0c41e0 commit 5a43734

Some content is hidden

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

53 files changed

+461
-361
lines changed

.travis.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
language: dart
22

33
dart:
4-
- dev
5-
- 2.2.0
4+
- dev
65

7-
dart_task:
8-
- test: --platform vm
9-
- test: --platform chrome
10-
- dartanalyzer
11-
- dartfmt
6+
jobs:
7+
include:
8+
- stage: analyze_and_format
9+
name: "Analyzer"
10+
dart: be/raw/latest
11+
os: linux
12+
script: dartanalyzer --enable-experiment=non-nullable --fatal-warnings --fatal-infos .
13+
- stage: analyze_and_format
14+
name: "Format"
15+
dart: be/raw/latest
16+
os: linux
17+
script: dartfmt -n --set-exit-if-changed .
18+
- stage: test
19+
name: "Vm Tests"
20+
dart: be/raw/latest
21+
os: linux
22+
script: pub run --enable-experiment=non-nullable test -p vm
23+
24+
stages:
25+
- analyze_and_format
26+
- test
1227

1328
# Only building master means that we don't run two builds for each pull request.
1429
branches:
15-
only: [master]
30+
only: [master, null_safety]
1631

1732
cache:
1833
directories:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.5.0-nullsafety
2+
3+
* Migrate this package to null safety.
4+
15
## 2.4.2
26

37
* `StreamQueue` starts listening immediately to broadcast strings.

analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ analyzer:
77
todo: ignore
88
# Lint provided by pkg:pedantic – should fix this!
99
unawaited_futures: ignore
10+
enable-experiment:
11+
- non-nullable
1012

1113
linter:
1214
rules:

lib/src/async_cache.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ class AsyncCache<T> {
2929
final Duration _duration;
3030

3131
/// Cached results of a previous [fetchStream] call.
32-
StreamSplitter<T> _cachedStreamSplitter;
32+
StreamSplitter<T>? _cachedStreamSplitter;
3333

3434
/// Cached results of a previous [fetch] call.
35-
Future<T> _cachedValueFuture;
35+
Future<T>? _cachedValueFuture;
3636

3737
/// Fires when the cache should be considered stale.
38-
Timer _stale;
38+
Timer? _stale;
3939

4040
/// Creates a cache that invalidates its contents after [duration] has passed.
4141
///
@@ -65,7 +65,7 @@ class AsyncCache<T> {
6565
await _cachedValueFuture;
6666
_startStaleTimer();
6767
}
68-
return _cachedValueFuture;
68+
return _cachedValueFuture!;
6969
}
7070

7171
/// Returns a cached stream from a previous call to [fetchStream], or runs
@@ -78,12 +78,12 @@ class AsyncCache<T> {
7878
if (_cachedValueFuture != null) {
7979
throw StateError('Previously used to cache via `fetch`');
8080
}
81-
_cachedStreamSplitter ??= StreamSplitter(
81+
var splitter = _cachedStreamSplitter ??= StreamSplitter(
8282
callback().transform(StreamTransformer.fromHandlers(handleDone: (sink) {
8383
_startStaleTimer();
8484
sink.close();
8585
})));
86-
return _cachedStreamSplitter.split();
86+
return splitter.split();
8787
}
8888

8989
/// Removes any cached value.

lib/src/cancelable_operation.dart

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CancelableOperation<T> {
3535
/// moment this [CancelableOperation] is created, regardless of whether
3636
/// [inner] has completed yet or not.
3737
factory CancelableOperation.fromFuture(Future<T> inner,
38-
{FutureOr Function() onCancel}) {
38+
{FutureOr Function()? onCancel}) {
3939
var completer = CancelableCompleter<T>(onCancel: onCancel);
4040
completer.complete(inner);
4141
return completer.operation;
@@ -55,7 +55,7 @@ class CancelableOperation<T> {
5555
value.then((value) {
5656
controller.add(value);
5757
controller.close();
58-
}, onError: (error, StackTrace stackTrace) {
58+
}, onError: (Object error, StackTrace stackTrace) {
5959
controller.addError(error, stackTrace);
6060
controller.close();
6161
});
@@ -68,8 +68,8 @@ class CancelableOperation<T> {
6868
/// If this operation completes, this completes to the same result as [value].
6969
/// If this operation is cancelled, the returned future waits for the future
7070
/// returned by [cancel], then completes to [cancellationValue].
71-
Future<T> valueOrCancellation([T cancellationValue]) {
72-
var completer = Completer<T>.sync();
71+
Future<T?> valueOrCancellation([T? cancellationValue]) {
72+
var completer = Completer<T?>.sync();
7373
value.then((result) => completer.complete(result),
7474
onError: completer.completeError);
7575

@@ -93,23 +93,24 @@ class CancelableOperation<T> {
9393
/// If [propagateCancel] is `true` and the returned operation is canceled then
9494
/// this operation is canceled. The default is `false`.
9595
CancelableOperation<R> then<R>(FutureOr<R> Function(T) onValue,
96-
{FutureOr<R> Function(Object, StackTrace) onError,
97-
FutureOr<R> Function() onCancel,
96+
{FutureOr<R> Function(Object, StackTrace)? onError,
97+
FutureOr<R> Function()? onCancel,
9898
bool propagateCancel = false}) {
9999
final completer =
100100
CancelableCompleter<R>(onCancel: propagateCancel ? cancel : null);
101101

102-
valueOrCancellation().then((T result) {
102+
valueOrCancellation().then((T? result) {
103103
if (!completer.isCanceled) {
104104
if (isCompleted) {
105-
completer.complete(Future.sync(() => onValue(result)));
105+
assert(result is T);
106+
completer.complete(Future.sync(() => onValue(result!)));
106107
} else if (onCancel != null) {
107108
completer.complete(Future.sync(onCancel));
108109
} else {
109110
completer._cancel();
110111
}
111112
}
112-
}, onError: (error, StackTrace stackTrace) {
113+
}, onError: (Object error, StackTrace stackTrace) {
113114
if (!completer.isCanceled) {
114115
if (onError != null) {
115116
completer.complete(Future.sync(() => onError(error, stackTrace)));
@@ -145,7 +146,7 @@ class CancelableCompleter<T> {
145146
final Completer<T> _inner;
146147

147148
/// The callback to call if the future is canceled.
148-
final FutureOrCallback _onCancel;
149+
final FutureOrCallback? _onCancel;
149150

150151
/// Creates a new completer for a [CancelableOperation].
151152
///
@@ -155,15 +156,14 @@ class CancelableCompleter<T> {
155156
///
156157
/// [onCancel] will be called synchronously when the operation is canceled.
157158
/// It's guaranteed to only be called once.
158-
CancelableCompleter({FutureOr Function() onCancel})
159+
CancelableCompleter({FutureOr Function()? onCancel})
159160
: _onCancel = onCancel,
160161
_inner = Completer<T>() {
161-
_operation = CancelableOperation<T>._(this);
162+
operation = CancelableOperation<T>._(this);
162163
}
163164

164165
/// The operation controlled by this completer.
165-
CancelableOperation<T> get operation => _operation;
166-
CancelableOperation<T> _operation;
166+
late final CancelableOperation<T> operation;
167167

168168
/// Whether the completer has completed.
169169
bool get isCompleted => _isCompleted;
@@ -180,7 +180,7 @@ class CancelableCompleter<T> {
180180
///
181181
/// If [value] is a [Future], this will complete to the result of that
182182
/// [Future] once it completes.
183-
void complete([FutureOr<T> value]) {
183+
void complete([FutureOr<T>? value]) {
184184
if (_isCompleted) throw StateError('Operation already completed');
185185
_isCompleted = true;
186186

@@ -200,14 +200,14 @@ class CancelableCompleter<T> {
200200
future.then((result) {
201201
if (_isCanceled) return;
202202
_inner.complete(result);
203-
}, onError: (error, StackTrace stackTrace) {
203+
}, onError: (Object error, StackTrace stackTrace) {
204204
if (_isCanceled) return;
205205
_inner.completeError(error, stackTrace);
206206
});
207207
}
208208

209209
/// Completes [operation] to [error].
210-
void completeError(Object error, [StackTrace stackTrace]) {
210+
void completeError(Object error, [StackTrace? stackTrace]) {
211211
if (_isCompleted) throw StateError('Operation already completed');
212212
_isCompleted = true;
213213

@@ -221,7 +221,8 @@ class CancelableCompleter<T> {
221221

222222
return _cancelMemo.runOnce(() {
223223
_isCanceled = true;
224-
if (_onCancel != null) return _onCancel();
224+
var onCancel = _onCancel;
225+
if (onCancel != null) return onCancel();
225226
});
226227
}
227228
}

lib/src/delegate/event_sink.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DelegatingEventSink<T> implements EventSink<T> {
3333
}
3434

3535
@override
36-
void addError(error, [StackTrace stackTrace]) {
36+
void addError(error, [StackTrace? stackTrace]) {
3737
_sink.addError(error, stackTrace);
3838
}
3939

lib/src/delegate/future.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ class DelegatingFuture<T> implements Future<T> {
2525
Stream<T> asStream() => _future.asStream();
2626

2727
@override
28-
Future<T> catchError(Function onError, {bool Function(Object error) test}) =>
28+
Future<T> catchError(Function onError, {bool Function(Object error)? test}) =>
2929
_future.catchError(onError, test: test);
3030

3131
@override
32-
Future<S> then<S>(FutureOr<S> Function(T) onValue, {Function onError}) =>
32+
Future<S> then<S>(FutureOr<S> Function(T) onValue, {Function? onError}) =>
3333
_future.then(onValue, onError: onError);
3434

3535
@override
3636
Future<T> whenComplete(FutureOr Function() action) =>
3737
_future.whenComplete(action);
3838

3939
@override
40-
Future<T> timeout(Duration timeLimit, {FutureOr<T> Function() onTimeout}) =>
40+
Future<T> timeout(Duration timeLimit, {FutureOr<T> Function()? onTimeout}) =>
4141
_future.timeout(timeLimit, onTimeout: onTimeout);
4242
}

lib/src/delegate/stream_sink.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class DelegatingStreamSink<T> implements StreamSink<T> {
3636
}
3737

3838
@override
39-
void addError(error, [StackTrace stackTrace]) {
39+
void addError(error, [StackTrace? stackTrace]) {
4040
_sink.addError(error, stackTrace);
4141
}
4242

lib/src/delegate/stream_subscription.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ class DelegatingStreamSubscription<T> implements StreamSubscription<T> {
3131
: TypeSafeStreamSubscription<T>(subscription);
3232

3333
@override
34-
void onData(void Function(T) handleData) {
34+
void onData(void Function(T)? handleData) {
3535
_source.onData(handleData);
3636
}
3737

3838
@override
39-
void onError(Function handleError) {
39+
void onError(Function? handleError) {
4040
_source.onError(handleError);
4141
}
4242

4343
@override
44-
void onDone(void Function() handleDone) {
44+
void onDone(void Function()? handleDone) {
4545
_source.onDone(handleDone);
4646
}
4747

4848
@override
49-
void pause([Future resumeFuture]) {
49+
void pause([Future? resumeFuture]) {
5050
_source.pause(resumeFuture);
5151
}
5252

@@ -59,7 +59,7 @@ class DelegatingStreamSubscription<T> implements StreamSubscription<T> {
5959
Future cancel() => _source.cancel();
6060

6161
@override
62-
Future<E> asFuture<E>([E futureValue]) => _source.asFuture(futureValue);
62+
Future<E> asFuture<E>([E? futureValue]) => _source.asFuture(futureValue);
6363

6464
@override
6565
bool get isPaused => _source.isPaused;

lib/src/future_group.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ class FutureGroup<T> implements Sink<Future<T>> {
4444
Stream get onIdle =>
4545
(_onIdleController ??= StreamController.broadcast(sync: true)).stream;
4646

47-
StreamController _onIdleController;
47+
StreamController? _onIdleController;
4848

4949
/// The values emitted by the futures that have been added to the group, in
5050
/// the order they were added.
5151
///
5252
/// The slots for futures that haven't completed yet are `null`.
53-
final _values = <T>[];
53+
final _values = <T?>[];
5454

5555
/// Wait for [task] to complete.
5656
@override
@@ -71,12 +71,13 @@ class FutureGroup<T> implements Sink<Future<T>> {
7171
_values[index] = value;
7272

7373
if (_pending != 0) return null;
74-
if (_onIdleController != null) _onIdleController.add(null);
74+
var onIdleController = _onIdleController;
75+
if (onIdleController != null) onIdleController.add(null);
7576

7677
if (!_closed) return null;
77-
if (_onIdleController != null) _onIdleController.close();
78-
_completer.complete(_values);
79-
}).catchError((error, StackTrace stackTrace) {
78+
if (onIdleController != null) onIdleController.close();
79+
_completer.complete(_values.whereType<T>().toList());
80+
}).catchError((Object error, StackTrace stackTrace) {
8081
if (_completer.isCompleted) return null;
8182
_completer.completeError(error, stackTrace);
8283
});
@@ -89,6 +90,6 @@ class FutureGroup<T> implements Sink<Future<T>> {
8990
_closed = true;
9091
if (_pending != 0) return;
9192
if (_completer.isCompleted) return;
92-
_completer.complete(_values);
93+
_completer.complete(_values.whereType<T>().toList());
9394
}
9495
}

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