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 part of dart.async; | 5 part of dart.async; |
6 | 6 |
7 /** The onValue and onError handlers return either a value or a future */ | 7 /** The onValue and onError handlers return either a value or a future */ |
8 typedef dynamic _FutureOnValue<T>(T value); | 8 typedef dynamic _FutureOnValue<T>(T value); |
9 /** Test used by [Future.catchError] to handle skip some errors. */ | 9 /** Test used by [Future.catchError] to handle skip some errors. */ |
10 typedef bool _FutureErrorTest(var error); | 10 typedef bool _FutureErrorTest(var error); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 set _isChained(bool value) { | 195 set _isChained(bool value) { |
196 if (value) { | 196 if (value) { |
197 assert(!_isComplete); | 197 assert(!_isComplete); |
198 _state = _CHAINED; | 198 _state = _CHAINED; |
199 } else { | 199 } else { |
200 assert(_isChained); | 200 assert(_isChained); |
201 _state = _INCOMPLETE; | 201 _state = _INCOMPLETE; |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 Future then(f(T value), { Function onError }) { | 205 Future/*<S>*/ then/*<S>*/(/*=S*/ f(T value), { Function onError }) { |
206 _Future result = new _Future(); | 206 _Future/*<S>*/ result = new _Future(); |
207 if (!identical(result._zone, _ROOT_ZONE)) { | 207 if (!identical(result._zone, _ROOT_ZONE)) { |
208 f = result._zone.registerUnaryCallback(f); | 208 f = result._zone.registerUnaryCallback(f); |
209 if (onError != null) { | 209 if (onError != null) { |
210 onError = _registerErrorHandler(onError, result._zone); | 210 onError = _registerErrorHandler(onError, result._zone); |
211 } | 211 } |
212 } | 212 } |
213 _addListener(new _FutureListener.then(result, f, onError)); | 213 _addListener(new _FutureListener.then(result, f, onError)); |
214 return result; | 214 return result; |
215 } | 215 } |
216 | 216 |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 } | 642 } |
643 }, onError: (e, s) { | 643 }, onError: (e, s) { |
644 if (timer.isActive) { | 644 if (timer.isActive) { |
645 timer.cancel(); | 645 timer.cancel(); |
646 result._completeError(e, s); | 646 result._completeError(e, s); |
647 } | 647 } |
648 }); | 648 }); |
649 return result; | 649 return result; |
650 } | 650 } |
651 } | 651 } |
OLD | NEW |