From e52b2654ad946d9ba0412c74e4a7b836a51408f2 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 1 May 2018 15:56:11 -0700 Subject: [PATCH 1/2] Fix Dart 2 runtime errors Closes #57 --- CHANGELOG.md | 4 ++++ lib/src/result/capture_sink.dart | 2 +- lib/src/result/capture_transformer.dart | 9 +++------ lib/src/stream_splitter.dart | 2 +- pubspec.yaml | 2 +- test/result/result_test.dart | 9 ++++----- test/stream_completer_test.dart | 4 ++-- test/stream_group_test.dart | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0807821..dc79f29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.7 + +* Fix Dart 2 runtime errors. + ## 2.0.6 * Add further support for Dart 2.0 library changes to `Stream`. diff --git a/lib/src/result/capture_sink.dart b/lib/src/result/capture_sink.dart index c85b553..742c160 100644 --- a/lib/src/result/capture_sink.dart +++ b/lib/src/result/capture_sink.dart @@ -13,7 +13,7 @@ class CaptureSink implements EventSink { CaptureSink(EventSink> sink) : _sink = sink; void add(T value) { - _sink.add(new Result.value(value)); + _sink.add(new Result.value(value)); } void addError(Object error, [StackTrace stackTrace]) { diff --git a/lib/src/result/capture_transformer.dart b/lib/src/result/capture_transformer.dart index 5933f0c..b9a538a 100644 --- a/lib/src/result/capture_transformer.dart +++ b/lib/src/result/capture_transformer.dart @@ -14,10 +14,7 @@ import 'capture_sink.dart'; class CaptureStreamTransformer extends StreamTransformerBase> { const CaptureStreamTransformer(); - Stream> bind(Stream source) { - return new Stream>.eventTransformed(source, _createSink); - } - - // Since Stream.eventTransformed is not generic, this method can be static. - static EventSink _createSink(EventSink sink) => new CaptureSink(sink); + Stream> bind(Stream source) => + new Stream>.eventTransformed( + source, (sink) => new CaptureSink(sink)); } diff --git a/lib/src/stream_splitter.dart b/lib/src/stream_splitter.dart index ac4260d..3616501 100644 --- a/lib/src/stream_splitter.dart +++ b/lib/src/stream_splitter.dart @@ -60,7 +60,7 @@ class StreamSplitter { static List> splitFrom(Stream stream, [int count]) { if (count == null) count = 2; var splitter = new StreamSplitter(stream); - var streams = new List.generate(count, (_) => splitter.split()); + var streams = new List>.generate(count, (_) => splitter.split()); splitter.close(); return streams; } diff --git a/pubspec.yaml b/pubspec.yaml index e8dafaa..dee58d0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: async -version: 2.0.6 +version: 2.0.7 author: Dart Team description: Utility functions and classes related to the 'dart:async' library. homepage: https://www.github.com/dart-lang/async diff --git a/test/result/result_test.dart b/test/result/result_test.dart index 210ae3f..23c9f63 100644 --- a/test/result/result_test.dart +++ b/test/result/result_test.dart @@ -173,8 +173,8 @@ void main() { }); test("capture stream", () { - StreamController c = new StreamController(); - Stream stream = Result.captureStream(c.stream); + var c = new StreamController(); + var stream = Result.captureStream(c.stream); var expectedList = new Queue.from([ new Result.value(42), new Result.error("BAD", stack), @@ -185,9 +185,8 @@ void main() { expectResult(actual, expectedList.removeFirst()); } - stream.listen(expectAsync1(listener, count: 3), onError: (e, s) { - fail("Unexpected error: $e"); - }, onDone: expectAsync0(() {}), cancelOnError: true); + stream.listen(expectAsync1(listener, count: 3), + onDone: expectAsync0(() {}), cancelOnError: true); c.add(42); c.addError("BAD", stack); c.add(37); diff --git a/test/stream_completer_test.dart b/test/stream_completer_test.dart index 2e9ff9b..4f30a7a 100644 --- a/test/stream_completer_test.dart +++ b/test/stream_completer_test.dart @@ -140,7 +140,7 @@ main() { test("cancelOnError true when listening before linking stream", () async { var completer = new StreamCompleter(); - var lastEvent = -1; + Object lastEvent = -1; var controller = new StreamController(); completer.stream.listen((value) { expect(value, lessThan(3)); @@ -173,7 +173,7 @@ main() { test("cancelOnError true when listening after linking stream", () async { var completer = new StreamCompleter(); - var lastEvent = -1; + Object lastEvent = -1; var controller = new StreamController(); completer.setSourceStream(controller.stream); controller.add(1); diff --git a/test/stream_group_test.dart b/test/stream_group_test.dart index 65ddb42..95eb8c1 100644 --- a/test/stream_group_test.dart +++ b/test/stream_group_test.dart @@ -49,7 +49,7 @@ main() { expect(streamGroup.close(), completes); var transformed = streamGroup.stream.transform( - new StreamTransformer.fromHandlers( + new StreamTransformer.fromHandlers( handleError: (error, _, sink) => sink.add("error: $error"))); expect(transformed.toList(), completion(equals(["error: first", "error: second"]))); @@ -72,7 +72,7 @@ main() { expect(streamGroup.close(), completes); var transformed = streamGroup.stream.transform( - new StreamTransformer.fromHandlers( + new StreamTransformer.fromHandlers( handleData: (data, sink) => sink.add("data: $data"), handleError: (error, _, sink) => sink.add("error: $error"))); expect( From 560602e20edb9a91661a2ea4a4d7667d84d244c8 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 2 May 2018 12:54:22 -0700 Subject: [PATCH 2/2] Add -dev We don't want to release this until #56 lands. --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index dee58d0..ecf5c8a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: async -version: 2.0.7 +version: 2.0.7-dev author: Dart Team description: Utility functions and classes related to the 'dart:async' library. homepage: https://www.github.com/dart-lang/async