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 deprecatedFutureValue(_FutureImpl future) => future._resultOrListeners; | 7 deprecatedFutureValue(_FutureImpl future) => future._resultOrListeners; |
8 | 8 |
9 | 9 |
10 class _CompleterImpl<T> implements Completer<T> { | 10 class _CompleterImpl<T> implements Completer<T> { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 } | 79 } |
80 | 80 |
81 factory _FutureImpl.wait(Iterable<Future> futures) { | 81 factory _FutureImpl.wait(Iterable<Future> futures) { |
82 // TODO(ajohnsen): can we do better wrt the generic type T? | 82 // TODO(ajohnsen): can we do better wrt the generic type T? |
83 if (futures.isEmpty) { | 83 if (futures.isEmpty) { |
84 return new Future<List>.immediate(const []); | 84 return new Future<List>.immediate(const []); |
85 } | 85 } |
86 | 86 |
87 Completer completer = new Completer<List>(); | 87 Completer completer = new Completer<List>(); |
88 int remaining = futures.length; | 88 int remaining = futures.length; |
89 List values = new List(futures.length); | 89 List values = new List.fixedLength(futures.length); |
90 | 90 |
91 // As each future completes, put its value into the corresponding | 91 // As each future completes, put its value into the corresponding |
92 // position in the list of values. | 92 // position in the list of values. |
93 int i = 0; | 93 int i = 0; |
94 for (Future future in futures) { | 94 for (Future future in futures) { |
95 int pos = i++; | 95 int pos = i++; |
96 future.then((Object value) { | 96 future.then((Object value) { |
97 values[pos] = value; | 97 values[pos] = value; |
98 if (--remaining == 0) { | 98 if (--remaining == 0) { |
99 completer.complete(values); | 99 completer.complete(values); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 _FutureWrapper(this._future); | 371 _FutureWrapper(this._future); |
372 | 372 |
373 Future then(function(T value)) => _future.then(function); | 373 Future then(function(T value)) => _future.then(function); |
374 Future catchError(function(AsyncError error), {bool test(var error)}) { | 374 Future catchError(function(AsyncError error), {bool test(var error)}) { |
375 return _future.catchError(function, test: test); | 375 return _future.catchError(function, test: test); |
376 } | 376 } |
377 Future subscribe({onValue(T value), onError(AsyncError error)}) { | 377 Future subscribe({onValue(T value), onError(AsyncError error)}) { |
378 _future.subscribe(onValue: onValue, onError: onError); | 378 _future.subscribe(onValue: onValue, onError: onError); |
379 } | 379 } |
380 } | 380 } |
OLD | NEW |