OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 import 'package:async_helper/async_helper.dart'; |
| 6 import "package:expect/expect.dart"; |
| 7 import 'dart:async'; |
| 8 import 'catch_errors.dart'; |
| 9 |
| 10 main() { |
| 11 asyncStart(); |
| 12 Completer done = new Completer(); |
| 13 |
| 14 var events = []; |
| 15 StreamController controller; |
| 16 Stream stream; |
| 17 // Test `StreamController.broadcast` streams. |
| 18 catchErrors(() { |
| 19 catchErrors(() { |
| 20 controller = new StreamController.broadcast(); |
| 21 |
| 22 // Listen to the stream from the inner zone. |
| 23 controller.stream |
| 24 .map((x) { |
| 25 events.add("map $x"); |
| 26 return x + 100; |
| 27 }) |
| 28 .transform(new StreamTransformer.fromHandlers( |
| 29 handleError: (e, st, sink) { sink.add("error $e"); })) |
| 30 .listen((x) { events.add("stream $x"); }); |
| 31 |
| 32 }).listen((x) { events.add(x); }) |
| 33 .asFuture().then((_) { Expect.fail("Unexpected callback"); }); |
| 34 |
| 35 // Listen to the stream from the outer zone. |
| 36 controller.stream.listen((x) { events.add("stream2 $x"); }, |
| 37 onError: (x) { events.add("stream2 error $x"); }); |
| 38 |
| 39 // Feed the controller. |
| 40 controller.add(1); |
| 41 controller.addError("inner stream"); |
| 42 new Future.error("outer error"); |
| 43 controller.close(); |
| 44 }).listen((x) { |
| 45 events.add("outer: $x"); |
| 46 if (x == "outer error") done.complete(true); |
| 47 }, |
| 48 onDone: () { Expect.fail("Unexpected callback"); }); |
| 49 |
| 50 done.future.whenComplete(() { |
| 51 // Give handlers time to run. |
| 52 Timer.run(() { |
| 53 Expect.listEquals(["map 1", |
| 54 "stream 101", |
| 55 "stream2 1", |
| 56 "stream error inner stream", |
| 57 "stream2 error inner stream", |
| 58 "outer: outer error", |
| 59 ], |
| 60 events); |
| 61 asyncEnd(); |
| 62 }); |
| 63 }); |
| 64 } |
OLD | NEW |