OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "dart:async"; | 5 import "dart:async"; |
6 | 6 |
7 import "package:async/async.dart" show SubscriptionStream; | 7 import "package:async/async.dart" show SubscriptionStream; |
8 import "package:test/test.dart"; | 8 import "package:test/test.dart"; |
9 | 9 |
10 import "utils.dart"; | 10 import "utils.dart"; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 setUp(() { | 76 setUp(() { |
77 var source = createErrorStream(); | 77 var source = createErrorStream(); |
78 var sourceSubscription = source.listen(null, | 78 var sourceSubscription = source.listen(null, |
79 cancelOnError: sourceCancels); | 79 cancelOnError: sourceCancels); |
80 subscriptionStream = new SubscriptionStream<int>(sourceSubscription); | 80 subscriptionStream = new SubscriptionStream<int>(sourceSubscription); |
81 }); | 81 }); |
82 | 82 |
83 test("- subscriptionStream: no", () async { | 83 test("- subscriptionStream: no", () async { |
84 var done = new Completer(); | 84 var done = new Completer(); |
85 var events = []; | 85 var events = []; |
86 var subscription = subscriptionStream.listen(events.add, | 86 subscriptionStream.listen(events.add, |
87 onError: events.add, | 87 onError: events.add, |
88 onDone: done.complete, | 88 onDone: done.complete, |
89 cancelOnError: false); | 89 cancelOnError: false); |
90 var expected = [1, 2, "To err is divine!"]; | 90 var expected = [1, 2, "To err is divine!"]; |
91 if (sourceCancels) { | 91 if (sourceCancels) { |
92 var timeout = done.future.timeout(const Duration(milliseconds: 5), | 92 var timeout = done.future.timeout(const Duration(milliseconds: 5), |
93 onTimeout: () => true); | 93 onTimeout: () => true); |
94 expect(await timeout, true); | 94 expect(await timeout, true); |
95 } else { | 95 } else { |
96 expected.add(4); | 96 expected.add(4); |
97 await done.future; | 97 await done.future; |
98 } | 98 } |
99 expect(events, expected); | 99 expect(events, expected); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 controller.add(4); | 167 controller.add(4); |
168 await flushMicrotasks(); | 168 await flushMicrotasks(); |
169 controller.close(); | 169 controller.close(); |
170 }(); | 170 }(); |
171 return controller.stream; | 171 return controller.stream; |
172 } | 172 } |
173 | 173 |
174 Stream<int> createLongStream() async* { | 174 Stream<int> createLongStream() async* { |
175 for (int i = 0; i < 200; i++) yield i; | 175 for (int i = 0; i < 200; i++) yield i; |
176 } | 176 } |
OLD | NEW |