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 /** | 5 /** |
6 * A [Future] is used to obtain a value sometime in the future. Receivers of a | 6 * A [Future] is used to obtain a value sometime in the future. Receivers of a |
7 * [Future] can obtain the value by passing a callback to [then]. For example: | 7 * [Future] can obtain the value by passing a callback to [then]. For example: |
8 * | 8 * |
9 * Future<int> future = getFutureFromSomewhere(); | 9 * Future<int> future = getFutureFromSomewhere(); |
10 * future.then((value) { | 10 * future.then((value) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 * will receive it. | 116 * will receive it. |
117 * | 117 * |
118 * If an exception occurs (received by this future, thrown by | 118 * If an exception occurs (received by this future, thrown by |
119 * [transformation], or received by the future returned by [transformation]) | 119 * [transformation], or received by the future returned by [transformation]) |
120 * then the returned future will receive the exception. | 120 * then the returned future will receive the exception. |
121 * | 121 * |
122 * You must not add exception handlers to [this] future prior to calling | 122 * You must not add exception handlers to [this] future prior to calling |
123 * chain, and any you add afterwards will not be invoked. | 123 * chain, and any you add afterwards will not be invoked. |
124 */ | 124 */ |
125 Future chain(Future transformation(T value)); | 125 Future chain(Future transformation(T value)); |
126 | |
127 /** | |
128 * A future representing [transformation] applied to this future's exception. | |
129 * This can be used to "catch" an exception coming from `this` and translate | |
130 * it to a more appropriate exception which will then be sent to the | |
131 * returned future. | |
132 * | |
133 * If this future gets a value, it simply completes to that same value. If an | |
134 * exception occurs, then [transformation] will be called with the exception | |
135 * value. | |
136 * | |
137 * If [transformation] itself throws an exception, then the returned future | |
138 * completes with that exception. If it returns `true`, then the exception is | |
139 * considered handled and is not propagated to the returned future. If it | |
140 * returns anything else, the original exception will be propagated. | |
Siggi Cherem (dart-lang)
2012/09/04 20:17:52
thinking about the control flow of this and how si
Bob Nystrom
2012/09/04 21:14:43
Works for me. Done.
| |
141 */ | |
142 Future transformException(bool transformation(Object exception)); | |
nweiz
2012/09/04 20:26:14
It seems like this should just be the default beha
Bob Nystrom
2012/09/04 21:14:43
I'm trying to keep this change as minimally invasi
nweiz
2012/09/04 21:35:35
Sure, seems fine.
| |
126 } | 143 } |
127 | 144 |
128 | 145 |
129 /** | 146 /** |
130 * A [Completer] is used to produce [Future]s and supply their value when it | 147 * A [Completer] is used to produce [Future]s and supply their value when it |
131 * becomes available. | 148 * becomes available. |
132 * | 149 * |
133 * A service that provides values to callers, and wants to return [Future]s can | 150 * A service that provides values to callers, and wants to return [Future]s can |
134 * use a [Completer] as follows: | 151 * use a [Completer] as follows: |
135 * | 152 * |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 future.handleException((exception) { | 236 future.handleException((exception) { |
220 if (!result.isComplete) { | 237 if (!result.isComplete) { |
221 completer.completeException(exception, future.stackTrace); | 238 completer.completeException(exception, future.stackTrace); |
222 } | 239 } |
223 return true; | 240 return true; |
224 }); | 241 }); |
225 } | 242 } |
226 return result; | 243 return result; |
227 } | 244 } |
228 } | 245 } |
OLD | NEW |