| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library future_test; | 5 library future_test; |
| 6 | 6 |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 | 10 |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 }); | 869 }); |
| 870 | 870 |
| 871 }, onError: (int index, s) { | 871 }, onError: (int index, s) { |
| 872 Expect.isTrue(index == 0 || index == 2, "$index"); | 872 Expect.isTrue(index == 0 || index == 2, "$index"); |
| 873 Expect.isFalse(uncaughts[index]); | 873 Expect.isFalse(uncaughts[index]); |
| 874 uncaughts[index] = true; | 874 uncaughts[index] = true; |
| 875 asyncEnd(); | 875 asyncEnd(); |
| 876 }); | 876 }); |
| 877 } | 877 } |
| 878 | 878 |
| 879 void testWaitSyncError() { |
| 880 var cms = const Duration(milliseconds: 100); |
| 881 var cleanups = new List.filled(3, false); |
| 882 var uncaughts = new List.filled(3, false); |
| 883 asyncStart(); |
| 884 asyncStart(); |
| 885 runZoned(() { |
| 886 Future.wait(new Iterable.generate(5, (i) { |
| 887 if (i != 3) return new Future.delayed(cms * (i + 1), () => i); |
| 888 throw "throwing synchronously in iterable"; |
| 889 }), cleanUp: (index) { |
| 890 Expect.isFalse(cleanups[index]); |
| 891 cleanups[index] = true; |
| 892 if (cleanups.every((x) => x)) asyncEnd(); |
| 893 }); |
| 894 }, onError: (e, s) { |
| 895 asyncEnd(); |
| 896 }); |
| 897 } |
| 898 |
| 879 void testBadFuture() { | 899 void testBadFuture() { |
| 880 var bad = new BadFuture(); | 900 var bad = new BadFuture(); |
| 881 // Completing with bad future (then call throws) puts error in result. | 901 // Completing with bad future (then call throws) puts error in result. |
| 882 asyncStart(); | 902 asyncStart(); |
| 883 Completer completer = new Completer(); | 903 Completer completer = new Completer(); |
| 884 completer.complete(bad); | 904 completer.complete(bad); |
| 885 completer.future.then((_) { Expect.fail("unreachable"); }, | 905 completer.future.then((_) { Expect.fail("unreachable"); }, |
| 886 onError: (e, s) { | 906 onError: (e, s) { |
| 887 Expect.isTrue(completer.isCompleted); | 907 Expect.isTrue(completer.isCompleted); |
| 888 asyncEnd(); | 908 asyncEnd(); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 testFutureCatchRethrowsAsync(); | 1088 testFutureCatchRethrowsAsync(); |
| 1069 | 1089 |
| 1070 testChainedFutureValue(); | 1090 testChainedFutureValue(); |
| 1071 testChainedFutureValueDelay(); | 1091 testChainedFutureValueDelay(); |
| 1072 testChainedFutureError(); | 1092 testChainedFutureError(); |
| 1073 | 1093 |
| 1074 testSyncFuture_i13368(); | 1094 testSyncFuture_i13368(); |
| 1075 | 1095 |
| 1076 testWaitCleanUp(); | 1096 testWaitCleanUp(); |
| 1077 testWaitCleanUpError(); | 1097 testWaitCleanUpError(); |
| 1098 testWaitSyncError(); |
| 1078 | 1099 |
| 1079 testBadFuture(); | 1100 testBadFuture(); |
| 1080 | 1101 |
| 1081 testTypes(); | 1102 testTypes(); |
| 1082 | 1103 |
| 1083 testAnyValue(); | 1104 testAnyValue(); |
| 1084 testAnyError(); | 1105 testAnyError(); |
| 1085 testAnyIgnoreIncomplete(); | 1106 testAnyIgnoreIncomplete(); |
| 1086 testAnyIgnoreError(); | 1107 testAnyIgnoreError(); |
| 1087 | 1108 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 Future whenComplete(action()) { | 1160 Future whenComplete(action()) { |
| 1140 return new Future.microtask(action).then((_) => this); | 1161 return new Future.microtask(action).then((_) => this); |
| 1141 } | 1162 } |
| 1142 Stream asStream() { | 1163 Stream asStream() { |
| 1143 return (new StreamController()..add(_result)..close()).stream; | 1164 return (new StreamController()..add(_result)..close()).stream; |
| 1144 } | 1165 } |
| 1145 Future timeout(Duration duration, {onTimeout()}) { | 1166 Future timeout(Duration duration, {onTimeout()}) { |
| 1146 return this; | 1167 return this; |
| 1147 } | 1168 } |
| 1148 } | 1169 } |
| OLD | NEW |