| 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 /** | 7 /** |
| 8 * A [Future] is used to obtain a value sometime in the future. Receivers of a | 8 * A [Future] is used to obtain a value sometime in the future. Receivers of a |
| 9 * [Future] can obtain the value by passing a callback to [then]. For example: | 9 * [Future] can obtain the value by passing a callback to [then]. For example: |
| 10 * | 10 * |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 {bool test(Object error)}); | 95 {bool test(Object error)}); |
| 96 | 96 |
| 97 /** | 97 /** |
| 98 * Register a function to be called when this future completes. | 98 * Register a function to be called when this future completes. |
| 99 * | 99 * |
| 100 * The [action] function is called when this future completes, whether it | 100 * The [action] function is called when this future completes, whether it |
| 101 * does so with a value or with an error. | 101 * does so with a value or with an error. |
| 102 * | 102 * |
| 103 * This is the asynchronous equivalent of a "finally" block. | 103 * This is the asynchronous equivalent of a "finally" block. |
| 104 * | 104 * |
| 105 * If the call to [action] does not throw, the returned future is completed | 105 * The future returned by this call, [:f:], will complete the same way |
| 106 * with the same result as this future. | 106 * as this future unless an error occurs in the [action] call, or in |
| 107 * a [Future] returned by the [action] call. If the call to [action] |
| 108 * does not return a future, its return value is ignored. |
| 107 * | 109 * |
| 108 * If the call to [action] throws, the returned future is completed with the | 110 * If the call to [action] throws, then [:f:] is completed with the |
| 109 * thrown error. | 111 * thrown error. |
| 112 * |
| 113 * If the call to [action] returns a [Future], [:f2:], then completion of |
| 114 * [:f:] is delayed until [:f2:] completes. If [:f2:] completes with |
| 115 * an error, that will be the result of [:f:] too. |
| 110 */ | 116 */ |
| 111 Future<T> whenComplete(void action()); | 117 Future<T> whenComplete(action()); |
| 112 | 118 |
| 113 /** | 119 /** |
| 114 * Creates a [Stream] that sends [this]' completion value, data or error, to | 120 * Creates a [Stream] that sends [this]' completion value, data or error, to |
| 115 * its subscribers. The stream closes after the completion value. | 121 * its subscribers. The stream closes after the completion value. |
| 116 */ | 122 */ |
| 117 Stream<T> asStream(); | 123 Stream<T> asStream(); |
| 118 } | 124 } |
| 119 | 125 |
| 120 /** | 126 /** |
| 121 * A [Completer] is used to produce [Future]s and supply their value when it | 127 * A [Completer] is used to produce [Future]s and supply their value when it |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 */ | 191 */ |
| 186 static Future forEach(Iterable input, Future f(element)) { | 192 static Future forEach(Iterable input, Future f(element)) { |
| 187 var iterator = input.iterator; | 193 var iterator = input.iterator; |
| 188 Future nextElement(_) { | 194 Future nextElement(_) { |
| 189 if (!iterator.moveNext()) return new Future.immediate(null); | 195 if (!iterator.moveNext()) return new Future.immediate(null); |
| 190 return f(iterator.current).then(nextElement); | 196 return f(iterator.current).then(nextElement); |
| 191 } | 197 } |
| 192 return nextElement(null); | 198 return nextElement(null); |
| 193 } | 199 } |
| 194 } | 200 } |
| OLD | NEW |