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

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

Issue 10891022: Update corelib/ and lib/ to use the new try-catch syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | « corelib/src/expect.dart ('k') | lib/compiler/implementation/apiimpl.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 2012 Google Inc. All Rights Reserved. 1 // Copyright 2012 Google Inc. All Rights Reserved.
2 // Dart core library. 2 // Dart core library.
3 3
4 class FutureImpl<T> implements Future<T> { 4 class FutureImpl<T> implements Future<T> {
5 5
6 bool _isComplete = false; 6 bool _isComplete = false;
7 7
8 /** 8 /**
9 * Value that was provided to this Future by the Completer 9 * Value that was provided to this Future by the Completer
10 */ 10 */
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 } else { 103 } else {
104 _exceptionHandlers.add(onException); 104 _exceptionHandlers.add(onException);
105 } 105 }
106 } 106 }
107 107
108 void onComplete(void complete(Future<T> future)) { 108 void onComplete(void complete(Future<T> future)) {
109 if (_isComplete) { 109 if (_isComplete) {
110 try { 110 try {
111 complete(this); 111 complete(this);
112 } catch (final e) {} 112 } catch (e) {}
113 } else { 113 } else {
114 _completionListeners.add(complete); 114 _completionListeners.add(complete);
115 } 115 }
116 } 116 }
117 117
118 void _complete() { 118 void _complete() {
119 _isComplete = true; 119 _isComplete = true;
120 120
121 try { 121 try {
122 if (_exception !== null) { 122 if (_exception !== null) {
(...skipping 13 matching lines...) Expand all
136 } 136 }
137 } else { 137 } else {
138 if (!_exceptionHandled && _successListeners.length > 0) { 138 if (!_exceptionHandled && _successListeners.length > 0) {
139 throw _exception; 139 throw _exception;
140 } 140 }
141 } 141 }
142 } finally { 142 } finally {
143 for (Function listener in _completionListeners) { 143 for (Function listener in _completionListeners) {
144 try { 144 try {
145 listener(this); 145 listener(this);
146 } catch (final e) {} 146 } catch (e) {}
147 } 147 }
148 } 148 }
149 } 149 }
150 150
151 void _setValue(T value) { 151 void _setValue(T value) {
152 if (_isComplete) { 152 if (_isComplete) {
153 throw new FutureAlreadyCompleteException(); 153 throw new FutureAlreadyCompleteException();
154 } 154 }
155 _value = value; 155 _value = value;
156 _complete(); 156 _complete();
(...skipping 15 matching lines...) Expand all
172 Future transform(Function transformation) { 172 Future transform(Function transformation) {
173 final completer = new Completer(); 173 final completer = new Completer();
174 handleException((e) { 174 handleException((e) {
175 completer.completeException(e, this.stackTrace); 175 completer.completeException(e, this.stackTrace);
176 return true; 176 return true;
177 }); 177 });
178 then((v) { 178 then((v) {
179 var transformed = null; 179 var transformed = null;
180 try { 180 try {
181 transformed = transformation(v); 181 transformed = transformation(v);
182 } catch (final ex, final stackTrace) { 182 } catch (ex, stackTrace) {
183 completer.completeException(ex, stackTrace); 183 completer.completeException(ex, stackTrace);
184 return; 184 return;
185 } 185 }
186 completer.complete(transformed); 186 completer.complete(transformed);
187 }); 187 });
188 return completer.future; 188 return completer.future;
189 } 189 }
190 190
191 Future chain(Function transformation) { 191 Future chain(Function transformation) {
192 final completer = new Completer(); 192 final completer = new Completer();
193 handleException((e) { 193 handleException((e) {
194 completer.completeException(e, this.stackTrace); 194 completer.completeException(e, this.stackTrace);
195 return true; 195 return true;
196 }); 196 });
197 then((v) { 197 then((v) {
198 var future = null; 198 var future = null;
199 try { 199 try {
200 future = transformation(v); 200 future = transformation(v);
201 } catch (final ex, final stackTrace) { 201 } catch (ex, stackTrace) {
202 completer.completeException(ex, stackTrace); 202 completer.completeException(ex, stackTrace);
203 return; 203 return;
204 } 204 }
205 future.handleException((e) { 205 future.handleException((e) {
206 completer.completeException(e, future.stackTrace); 206 completer.completeException(e, future.stackTrace);
207 return true; 207 return true;
208 }); 208 });
209 future.then((b) => completer.complete(b)); 209 future.then((b) => completer.complete(b));
210 }); 210 });
211 return completer.future; 211 return completer.future;
(...skipping 11 matching lines...) Expand all
223 } 223 }
224 224
225 void complete(T value) { 225 void complete(T value) {
226 _futureImpl._setValue(value); 226 _futureImpl._setValue(value);
227 } 227 }
228 228
229 void completeException(Object exception, [Object stackTrace]) { 229 void completeException(Object exception, [Object stackTrace]) {
230 _futureImpl._setException(exception, stackTrace); 230 _futureImpl._setException(exception, stackTrace);
231 } 231 }
232 } 232 }
OLDNEW
« no previous file with comments | « corelib/src/expect.dart ('k') | lib/compiler/implementation/apiimpl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698