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

Side by Side Diff: lib/coreimpl/future_implementation.dart

Issue 10919146: Get rid of a lot of () for getters. (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 | « lib/coreimpl/duration_implementation.dart ('k') | lib/coreimpl/hash_map_set.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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 : _successListeners = [], 45 : _successListeners = [],
46 _exceptionHandlers = [], 46 _exceptionHandlers = [],
47 _completionListeners = []; 47 _completionListeners = [];
48 48
49 factory FutureImpl.immediate(T value) { 49 factory FutureImpl.immediate(T value) {
50 final res = new FutureImpl(); 50 final res = new FutureImpl();
51 res._setValue(value); 51 res._setValue(value);
52 return res; 52 return res;
53 } 53 }
54 54
55 T get value() { 55 T get value {
56 if (!isComplete) { 56 if (!isComplete) {
57 throw new FutureNotCompleteException(); 57 throw new FutureNotCompleteException();
58 } 58 }
59 if (_exception !== null) { 59 if (_exception !== null) {
60 throw _exception; 60 throw _exception;
61 } 61 }
62 return _value; 62 return _value;
63 } 63 }
64 64
65 Object get exception() { 65 Object get exception {
66 if (!isComplete) { 66 if (!isComplete) {
67 throw new FutureNotCompleteException(); 67 throw new FutureNotCompleteException();
68 } 68 }
69 return _exception; 69 return _exception;
70 } 70 }
71 71
72 Object get stackTrace() { 72 Object get stackTrace {
73 if (!isComplete) { 73 if (!isComplete) {
74 throw new FutureNotCompleteException(); 74 throw new FutureNotCompleteException();
75 } 75 }
76 return _stackTrace; 76 return _stackTrace;
77 } 77 }
78 78
79 bool get isComplete() { 79 bool get isComplete {
80 return _isComplete; 80 return _isComplete;
81 } 81 }
82 82
83 bool get hasValue() { 83 bool get hasValue {
84 return isComplete && _exception === null; 84 return isComplete && _exception === null;
85 } 85 }
86 86
87 void then(void onSuccess(T value)) { 87 void then(void onSuccess(T value)) {
88 if (hasValue) { 88 if (hasValue) {
89 onSuccess(value); 89 onSuccess(value);
90 } else if (!isComplete) { 90 } else if (!isComplete) {
91 _successListeners.add(onSuccess); 91 _successListeners.add(onSuccess);
92 } else if (!_exceptionHandled) { 92 } else if (!_exceptionHandled) {
93 throw _exception; 93 throw _exception;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 return completer.future; 231 return completer.future;
232 } 232 }
233 } 233 }
234 234
235 class CompleterImpl<T> implements Completer<T> { 235 class CompleterImpl<T> implements Completer<T> {
236 236
237 final FutureImpl<T> _futureImpl; 237 final FutureImpl<T> _futureImpl;
238 238
239 CompleterImpl() : _futureImpl = new FutureImpl() {} 239 CompleterImpl() : _futureImpl = new FutureImpl() {}
240 240
241 Future<T> get future() { 241 Future<T> get future {
242 return _futureImpl; 242 return _futureImpl;
243 } 243 }
244 244
245 void complete(T value) { 245 void complete(T value) {
246 _futureImpl._setValue(value); 246 _futureImpl._setValue(value);
247 } 247 }
248 248
249 void completeException(Object exception, [Object stackTrace]) { 249 void completeException(Object exception, [Object stackTrace]) {
250 _futureImpl._setException(exception, stackTrace); 250 _futureImpl._setException(exception, stackTrace);
251 } 251 }
252 } 252 }
OLDNEW
« no previous file with comments | « lib/coreimpl/duration_implementation.dart ('k') | lib/coreimpl/hash_map_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698