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

Side by Side Diff: corelib/src/implementation/future_implementation.dart

Issue 9007053: await in frog: partial support for try-catch blocks (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 8 years, 11 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 | frog/await/transformation.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 2011 Google Inc. All Rights Reserved. 1 // Copyright 2011 Google Inc. All Rights Reserved.
2 // Dart core library. 2 // Dart core library.
3 3
4 /** 4 /**
5 * Thrown if client tries to obtain value or exception 5 * Thrown if client tries to obtain value or exception
6 * before a future has completed. 6 * before a future has completed.
7 */ 7 */
8 class FutureNotCompleteException implements Exception { 8 class FutureNotCompleteException implements Exception {
9 FutureNotCompleteException() {} 9 FutureNotCompleteException() {}
10 String toString() => "Exception: future has not been completed";
10 } 11 }
11 12
12 /** 13 /**
13 * Thrown if a completer tries to set the value on 14 * Thrown if a completer tries to set the value on
14 * a future that is already complete. 15 * a future that is already complete.
15 */ 16 */
16 class FutureAlreadyCompleteException implements Exception { 17 class FutureAlreadyCompleteException implements Exception {
17 FutureAlreadyCompleteException() {} 18 FutureAlreadyCompleteException() {}
19 String toString() => "Exception: future already completed";
18 } 20 }
19 21
20 22
21 class FutureImpl<T> implements Future<T> { 23 class FutureImpl<T> implements Future<T> {
22 24
23 bool _isComplete; 25 bool _isComplete;
24 26
25 /** 27 /**
26 * Value that was provided to this Future by the Completer 28 * Value that was provided to this Future by the Completer
27 */ 29 */
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 return _isComplete; 76 return _isComplete;
75 } 77 }
76 78
77 bool get hasValue() { 79 bool get hasValue() {
78 return isComplete && _exception === null; 80 return isComplete && _exception === null;
79 } 81 }
80 82
81 void then(void onComplete(T value)) { 83 void then(void onComplete(T value)) {
82 if (hasValue) { 84 if (hasValue) {
83 onComplete(value); 85 onComplete(value);
84 } else { 86 } else if (!isComplete) {
85 _listeners.add(onComplete); 87 _listeners.add(onComplete);
88 } else if (!_exceptionHandled) {
89 throw _exception;
86 } 90 }
87 } 91 }
88 92
89 void handleException(void onException(Object exception)) { 93 void handleException(void onException(Object exception)) {
90 _exceptionHandlers.add(onException); 94 _exceptionHandlers.add(onException);
91 } 95 }
92 96
93 void _complete() { 97 void _complete() {
94 _isComplete = true; 98 _isComplete = true;
95 if (_exception !== null) { 99 if (_exception !== null) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 146 }
143 147
144 void complete(T value) { 148 void complete(T value) {
145 _futureImpl._setValue(value); 149 _futureImpl._setValue(value);
146 } 150 }
147 151
148 void completeException(var exception) { 152 void completeException(var exception) {
149 _futureImpl._setException(exception); 153 _futureImpl._setException(exception);
150 } 154 }
151 } 155 }
OLDNEW
« no previous file with comments | « no previous file | frog/await/transformation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698