| 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 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 // An evil future that completes with another future. | 1128 // An evil future that completes with another future. |
| 1129 class UglyFuture implements Future<dynamic> { | 1129 class UglyFuture implements Future<dynamic> { |
| 1130 final _result; | 1130 final _result; |
| 1131 UglyFuture(int badness) : | 1131 UglyFuture(int badness) : |
| 1132 _result = (badness == 0) ? 42 : new UglyFuture(badness - 1); | 1132 _result = (badness == 0) ? 42 : new UglyFuture(badness - 1); |
| 1133 Future then(action(value), {onError(error, StackTrace stack)}) { | 1133 Future then(action(value), {onError(error, StackTrace stack)}) { |
| 1134 var c = new Completer(); | 1134 var c = new Completer(); |
| 1135 c.complete(new Future.microtask(() => action(_result))); | 1135 c.complete(new Future.microtask(() => action(_result))); |
| 1136 return c.future; | 1136 return c.future; |
| 1137 } | 1137 } |
| 1138 Future catchError(onError, {test}) {} // Never an error. | 1138 Future catchError(onError, {test}) => this; // Never an error. |
| 1139 Future whenComplete(action()) { | 1139 Future whenComplete(action()) { |
| 1140 return new Future.microtask(action).then((_) => this); | 1140 return new Future.microtask(action).then((_) => this); |
| 1141 } | 1141 } |
| 1142 Stream asStream() { |
| 1143 return (new StreamController()..add(_result)..close()).stream; |
| 1144 } |
| 1145 Future timeout(Duration duration, {onTimeout()}) { |
| 1146 return this; |
| 1147 } |
| 1142 } | 1148 } |
| OLD | NEW |