Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Test the basic StreamController and StreamController.singleSubscription. | 5 // Test the basic StreamController and StreamController.singleSubscription. |
| 6 library stream_controller_async_test; | 6 library stream_controller_async_test; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 sink.add(42); | 654 sink.add(42); |
| 655 sink.addError("error"); | 655 sink.addError("error"); |
| 656 sink.addStream(new Stream.fromIterable([1, 2, 3, 4, 5])) | 656 sink.addStream(new Stream.fromIterable([1, 2, 3, 4, 5])) |
| 657 .then((_) { | 657 .then((_) { |
| 658 sink.add(43); | 658 sink.add(43); |
| 659 return sink.close(); | 659 return sink.close(); |
| 660 }) | 660 }) |
| 661 .then((_) { | 661 .then((_) { |
| 662 if (asBroadcast || broadcast) { | 662 if (asBroadcast || broadcast) { |
| 663 // The done-future of the sink completes when it passes | 663 // The done-future of the sink completes when it passes |
| 664 // the done event to the asBroadcastStream controller, which is | 664 // the done event to the asBroadcastStream controller, which is |
|
floitsch
2013/10/16 11:02:04
comment doesn't seem relevant anymore.
Lasse Reichstein Nielsen
2013/10/16 11:27:47
It's still relevant, but I reworded it a little.
| |
| 665 // before the final listener gets the event. | 665 // before the final listener gets the event. |
| 666 // Wait for the pause to end before testing the events. | 666 // Wait for the pause to end before testing the events. |
| 667 dynamic executeWhenPauseIsDone(Function f) { | 667 actual.onDone(() { |
| 668 if (!pauseIsDone) { | |
| 669 return new Future.delayed(const Duration(milliseconds: 50), () { | |
| 670 return executeWhenPauseIsDone(f); | |
| 671 }); | |
| 672 } | |
| 673 return f(); | |
| 674 } | |
| 675 return executeWhenPauseIsDone(() { | |
| 676 Expect.listEquals(expected.events, actual.events); | 668 Expect.listEquals(expected.events, actual.events); |
| 677 done(); | 669 done(); |
| 678 }); | 670 }); |
| 679 } else { | 671 } else { |
| 680 Expect.listEquals(expected.events, actual.events); | 672 Expect.listEquals(expected.events, actual.events); |
| 681 done(); | 673 done(); |
| 682 } | 674 } |
| 683 }); | 675 }); |
| 684 }); | 676 }); |
| 685 } | 677 } |
| 686 | 678 |
| 687 main() { | 679 main() { |
| 688 testController(); | 680 testController(); |
| 689 testSingleController(); | 681 testSingleController(); |
| 690 testExtraMethods(); | 682 testExtraMethods(); |
| 691 testPause(); | 683 testPause(); |
| 692 testRethrow(); | 684 testRethrow(); |
| 693 testBroadcastController(); | 685 testBroadcastController(); |
| 694 testAsBroadcast(); | 686 testAsBroadcast(); |
| 695 testSink(sync: true, broadcast: false, asBroadcast: false); | 687 testSink(sync: true, broadcast: false, asBroadcast: false); |
| 696 testSink(sync: true, broadcast: false, asBroadcast: true); | 688 testSink(sync: true, broadcast: false, asBroadcast: true); |
| 697 testSink(sync: true, broadcast: true, asBroadcast: false); | 689 testSink(sync: true, broadcast: true, asBroadcast: false); |
| 698 testSink(sync: false, broadcast: false, asBroadcast: false); | 690 testSink(sync: false, broadcast: false, asBroadcast: false); |
| 699 testSink(sync: false, broadcast: false, asBroadcast: true); | 691 testSink(sync: false, broadcast: false, asBroadcast: true); |
| 700 testSink(sync: false, broadcast: true, asBroadcast: false); | 692 testSink(sync: false, broadcast: true, asBroadcast: false); |
| 701 } | 693 } |
| OLD | NEW |