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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 * A future representing [transformation] applied to this future's value. | 97 * A future representing [transformation] applied to this future's value. |
98 * | 98 * |
99 * When this future gets a value, [transformation] will be called on the | 99 * When this future gets a value, [transformation] will be called on the |
100 * value, and the returned future will receive the result. | 100 * value, and the returned future will receive the result. |
101 * | 101 * |
102 * If an exception occurs (received by this future, or thrown by | 102 * If an exception occurs (received by this future, or thrown by |
103 * [transformation]) then the returned future will receive the exception. | 103 * [transformation]) then the returned future will receive the exception. |
104 * | 104 * |
105 * You must not add exception handlers to [this] future prior to calling | 105 * You must not add exception handlers to [this] future prior to calling |
106 * transform, and any you add afterwards will not be invoked. | 106 * transform, and any you add afterwards will not be invoked. |
107 * | |
108 * The [onException] parameter can be provided to control how exceptions | |
109 * received by this future or the transformation are handled. If an exception | |
110 * occures, [onException] will be called. If that throws an exception, the | |
111 * returned future will complete with that exception. If it returns `true`, | |
112 * then the exception is considered handled and is not propogated to the | |
113 * returned future. If it returns anything else, the original exception will | |
114 * be propogated. | |
107 */ | 115 */ |
108 Future transform(transformation(T value)); | 116 Future transform(transformation(T value), [onException(Object exception)]); |
Siggi Cherem (dart-lang)
2012/09/04 16:56:33
maybe use [bool onException(Object exception)]?
(a
| |
109 | 117 |
110 /** | 118 /** |
111 * A future representing an asynchronous transformation applied to this | 119 * A future representing an asynchronous transformation applied to this |
112 * future's value. [transformation] must return a Future. | 120 * future's value. [transformation] must return a Future. |
113 * | 121 * |
114 * When this future gets a value, [transformation] will be called on the | 122 * When this future gets a value, [transformation] will be called on the |
115 * value. When the resulting future gets a value, the returned future | 123 * value. When the resulting future gets a value, the returned future |
116 * will receive it. | 124 * will receive it. |
117 * | 125 * |
118 * If an exception occurs (received by this future, thrown by | 126 * If an exception occurs (received by this future, thrown by |
119 * [transformation], or received by the future returned by [transformation]) | 127 * [transformation], or received by the future returned by [transformation]) |
120 * then the returned future will receive the exception. | 128 * then the returned future will receive the exception. |
121 * | 129 * |
122 * You must not add exception handlers to [this] future prior to calling | 130 * You must not add exception handlers to [this] future prior to calling |
123 * chain, and any you add afterwards will not be invoked. | 131 * chain, and any you add afterwards will not be invoked. |
124 */ | 132 */ |
125 Future chain(Future transformation(T value)); | 133 Future chain(Future transformation(T value)); |
Siggi Cherem (dart-lang)
2012/09/04 16:56:33
+ onException :)
| |
126 } | 134 } |
127 | 135 |
128 | 136 |
129 /** | 137 /** |
130 * A [Completer] is used to produce [Future]s and supply their value when it | 138 * A [Completer] is used to produce [Future]s and supply their value when it |
131 * becomes available. | 139 * becomes available. |
132 * | 140 * |
133 * A service that provides values to callers, and wants to return [Future]s can | 141 * A service that provides values to callers, and wants to return [Future]s can |
134 * use a [Completer] as follows: | 142 * use a [Completer] as follows: |
135 * | 143 * |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 future.handleException((exception) { | 227 future.handleException((exception) { |
220 if (!result.isComplete) { | 228 if (!result.isComplete) { |
221 completer.completeException(exception, future.stackTrace); | 229 completer.completeException(exception, future.stackTrace); |
222 } | 230 } |
223 return true; | 231 return true; |
224 }); | 232 }); |
225 } | 233 } |
226 return result; | 234 return result; |
227 } | 235 } |
228 } | 236 } |
OLD | NEW |