Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: corelib/src/future.dart

Issue 9372008: patch from issue 9360020 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | corelib/src/implementation/future_implementation.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Dart core library. 5 // Dart core library.
6 6
7 7
8 /** 8 /**
9 * A Future is used to obtain a value sometime in the 9 * A Future is used to obtain a value sometime in the
10 * future. 10 * future.
11 * 11 *
12 * Receivers of a Future obtain the value by passing 12 * Receivers of a Future obtain the value by passing
13 * a callback to the 'then' method of Future. 13 * a callback to the 'then' method of Future.
14 * 14 *
15 * For example: 15 * For example:
16 * 16 *
17 * Future<int> future = getFutureFromSomewhere(); 17 * Future<int> future = getFutureFromSomewhere();
18 * future.then((value) { 18 * future.then((value) {
19 * print("I received the number " + value); 19 * print("I received the number " + value);
20 * }); 20 * });
21 * 21 *
22 */ 22 */
23 interface Future<T> default FutureImpl<T> { 23 interface Future<T> default FutureImpl<T> {
24 /** A future whose value is immediately available. */
25 Future.immediate(T value);
24 26
25 /** 27 /**
26 * The value this future provided. (If called when hasValue 28 * The value this future provided. (If called when hasValue
27 * is false, then throws an exception.) 29 * is false, then throws an exception.)
28 */ 30 */
29 T get value(); 31 T get value();
30 32
31 /** 33 /**
32 * Exception that occurred (null if no exception occured). (If called 34 * Exception that occurred (null if no exception occured). (If called
33 * before [isComplete] is true, then this exception property itself 35 * before [isComplete] is true, then this exception property itself
(...skipping 30 matching lines...) Expand all
64 * any calls to [then] (meaning that there are onComplete callbacks waiting 66 * any calls to [then] (meaning that there are onComplete callbacks waiting
65 * for the value), then the exception will be thrown when it is set. 67 * for the value), then the exception will be thrown when it is set.
66 * 68 *
67 * (In most cases it should not be necessary to call handleException, 69 * (In most cases it should not be necessary to call handleException,
68 * because the exception associated with this Future will propagate naturally 70 * because the exception associated with this Future will propagate naturally
69 * if the future's value is being consumed. Only call handleException if you 71 * if the future's value is being consumed. Only call handleException if you
70 * need to do some special local exception handling related to this 72 * need to do some special local exception handling related to this
71 * particular Future's value.) 73 * particular Future's value.)
72 */ 74 */
73 void handleException(bool onException(Object exception)); 75 void handleException(bool onException(Object exception));
76
77 /**
78 * A future representing [transformation] applied to this future's value.
79 *
80 * When this future gets a value, [transformation] will be called on the
81 * value, and the returned future will receive the result.
82 *
83 * If an exception occurs (received by this future, or thrown by
84 * [transformation]) then the returned future will receive the exception.
85 *
86 * You must not add exception handlers to [this] future prior to calling
87 * transform, and any you add afterwards will not be invoked.
88 */
89 Future transform(Function transformation);
90
91 /**
92 * A future representing an asynchronous transformation applied to this
93 * future's value. [transformation] must return a Future.
94 *
95 * When this future gets a value, [transformation] will be called on the
96 * value. When the resulting future gets a value, the returned future
97 * will receive it.
98 *
99 * If an exception occurs (received by this future, thrown by
100 * [transformation], or received by the future returned by [transformation])
101 * then the returned future will receive the exception.
102 *
103 * You must not add exception handlers to [this] future prior to calling
104 * chain, and any you add afterwards will not be invoked.
105 */
106 Future chain(Function transformation);
74 } 107 }
75 108
76 109
77 /** 110 /**
78 * A Completer is used to produce Future objects, and supply 111 * A Completer is used to produce Future objects, and supply
79 * a value to the Future object when the value becomes available. 112 * a value to the Future object when the value becomes available.
80 * 113 *
81 * A service that provides values to callers, and wants to return Future objects 114 * A service that provides values to callers, and wants to return Future objects
82 * rather than returning the values immediately, can use a Completer as follows: 115 * rather than returning the values immediately, can use a Completer as follows:
83 * 116 *
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // Special case where all the futures are already completed, 178 // Special case where all the futures are already completed,
146 // trigger the value now. 179 // trigger the value now.
147 if (futures.length == 0) { 180 if (futures.length == 0) {
148 completer.complete(values); 181 completer.complete(values);
149 } 182 }
150 183
151 return completer.future; 184 return completer.future;
152 } 185 }
153 } 186 }
154 187
OLDNEW
« no previous file with comments | « no previous file | corelib/src/implementation/future_implementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698