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

Commit

Permalink
Fix Dart 2 runtime errors (#58)
Browse files Browse the repository at this point in the history
Closes #57
  • Loading branch information
nex3 authored May 2, 2018
1 parent bc7e4a7 commit 7fb80b6
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/result/capture_sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CaptureSink<T> implements EventSink<T> {
CaptureSink(EventSink<Result<T>> sink) : _sink = sink;

void add(T value) {
_sink.add(new Result.value(value));
_sink.add(new Result<T>.value(value));
}

void addError(Object error, [StackTrace stackTrace]) {
Expand Down
9 changes: 3 additions & 6 deletions lib/src/result/capture_transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import 'capture_sink.dart';
class CaptureStreamTransformer<T> extends StreamTransformerBase<T, Result<T>> {
const CaptureStreamTransformer();

Stream<Result<T>> bind(Stream<T> source) {
return new Stream<Result<T>>.eventTransformed(source, _createSink);
}

// Since Stream.eventTransformed is not generic, this method can be static.
static EventSink _createSink(EventSink<Result> sink) => new CaptureSink(sink);
Stream<Result<T>> bind(Stream<T> source) =>
new Stream<Result<T>>.eventTransformed(
source, (sink) => new CaptureSink<T>(sink));
}
2 changes: 1 addition & 1 deletion lib/src/stream_splitter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class StreamSplitter<T> {
static List<Stream<T>> splitFrom<T>(Stream<T> stream, [int count]) {
if (count == null) count = 2;
var splitter = new StreamSplitter<T>(stream);
var streams = new List<Stream>.generate(count, (_) => splitter.split());
var streams = new List<Stream<T>>.generate(count, (_) => splitter.split());
splitter.close();
return streams;
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: async
version: 2.0.6
version: 2.0.7-dev
author: Dart Team <misc@dartlang.org>
description: Utility functions and classes related to the 'dart:async' library.
homepage: https://www.github.com/dart-lang/async
Expand Down
9 changes: 4 additions & 5 deletions test/result/result_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ void main() {
});

test("capture stream", () {
StreamController<int> c = new StreamController<int>();
Stream<Result> stream = Result.captureStream(c.stream);
var c = new StreamController<int>();
var stream = Result.captureStream(c.stream);
var expectedList = new Queue.from([
new Result.value(42),
new Result.error("BAD", stack),
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/stream_completer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/stream_group_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ main() {
expect(streamGroup.close(), completes);

var transformed = streamGroup.stream.transform(
new StreamTransformer.fromHandlers(
new StreamTransformer<String, String>.fromHandlers(
handleError: (error, _, sink) => sink.add("error: $error")));
expect(transformed.toList(),
completion(equals(["error: first", "error: second"])));
Expand All @@ -72,7 +72,7 @@ main() {
expect(streamGroup.close(), completes);

var transformed = streamGroup.stream.transform(
new StreamTransformer.fromHandlers(
new StreamTransformer<String, String>.fromHandlers(
handleData: (data, sink) => sink.add("data: $data"),
handleError: (error, _, sink) => sink.add("error: $error")));
expect(
Expand Down

0 comments on commit 7fb80b6

Please sign in to comment.