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 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 testType(name, future.whenComplete((){}), depth - 1); | 966 testType(name, future.whenComplete((){}), depth - 1); |
967 } | 967 } |
968 } | 968 } |
969 for (var value in [42, null]) { | 969 for (var value in [42, null]) { |
970 testType("Future($value)", | 970 testType("Future($value)", |
971 new Future<int>(() => value)); | 971 new Future<int>(() => value)); |
972 testType("Future.delayed($value)", | 972 testType("Future.delayed($value)", |
973 new Future<int>.delayed(Duration.ZERO, () => value)); | 973 new Future<int>.delayed(Duration.ZERO, () => value)); |
974 testType("Future.microtask($value)", | 974 testType("Future.microtask($value)", |
975 new Future<int>.microtask(() => value)); | 975 new Future<int>.microtask(() => value)); |
976 testType("Future.sync($value)", new Future<int>.sync(() => value)); /// 01:
ok | 976 testType("Future.sync($value)", new Future<int>.sync(() => value)); //# 01:
ok |
977 testType("Future.sync(future($value))", /// 01:
continued | 977 testType("Future.sync(future($value))", //# 01:
continued |
978 new Future<int>.sync(() async => new Future.value(value))); /// 01:
continued | 978 new Future<int>.sync(() async => new Future.value(value))); //# 01:
continued |
979 testType("Future.value($value)", new Future<int>.value(value)); | 979 testType("Future.value($value)", new Future<int>.value(value)); |
980 } | 980 } |
981 testType("Completer.future", new Completer<int>().future); | 981 testType("Completer.future", new Completer<int>().future); |
982 testType("Future.error", new Future<int>.error("ERR")..catchError((_){})); | 982 testType("Future.error", new Future<int>.error("ERR")..catchError((_){})); |
983 } | 983 } |
984 | 984 |
985 void testAnyValue() { | 985 void testAnyValue() { |
986 asyncStart(); | 986 asyncStart(); |
987 var cs = new List.generate(3, (_) => new Completer()); | 987 var cs = new List.generate(3, (_) => new Completer()); |
988 var result = Future.any(cs.map((x) => x.future)); | 988 var result = Future.any(cs.map((x) => x.future)); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 Future whenComplete(action()) { | 1198 Future whenComplete(action()) { |
1199 return new Future.microtask(action).then((_) => this); | 1199 return new Future.microtask(action).then((_) => this); |
1200 } | 1200 } |
1201 Stream asStream() { | 1201 Stream asStream() { |
1202 return (new StreamController()..add(_result)..close()).stream; | 1202 return (new StreamController()..add(_result)..close()).stream; |
1203 } | 1203 } |
1204 Future timeout(Duration duration, {onTimeout()}) { | 1204 Future timeout(Duration duration, {onTimeout()}) { |
1205 return this; | 1205 return this; |
1206 } | 1206 } |
1207 } | 1207 } |
OLD | NEW |