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 /** | 7 /** |
8 * An object representing a delayed computation. | 8 * An object representing a delayed computation. |
9 * | 9 * |
10 * A [Future] is used to represent a potential value, or error, | 10 * A [Future] is used to represent a potential value, or error, |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 * If calling [computation] throws, the created future will complete with the | 218 * If calling [computation] throws, the created future will complete with the |
219 * error. | 219 * error. |
220 * | 220 * |
221 * See also [Completer] for a way to create and complete a future at a | 221 * See also [Completer] for a way to create and complete a future at a |
222 * later time that isn't necessarily after a known fixed duration. | 222 * later time that isn't necessarily after a known fixed duration. |
223 */ | 223 */ |
224 factory Future.delayed(Duration duration, [computation()]) { | 224 factory Future.delayed(Duration duration, [computation()]) { |
225 _Future result = new _Future<T>(); | 225 _Future result = new _Future<T>(); |
226 new Timer(duration, () { | 226 new Timer(duration, () { |
227 try { | 227 try { |
228 result._complete(computation == null ? null : computation()); | 228 result._complete(computation?.call()); |
229 } catch (e, s) { | 229 } catch (e, s) { |
230 _completeWithErrorCallback(result, e, s); | 230 _completeWithErrorCallback(result, e, s); |
231 } | 231 } |
232 }); | 232 }); |
233 return result; | 233 return result; |
234 } | 234 } |
235 | 235 |
236 /** | 236 /** |
237 * Wait for all the given futures to complete and collect their values. | 237 * Wait for all the given futures to complete and collect their values. |
238 * | 238 * |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 if (replacement != null) { | 745 if (replacement != null) { |
746 error = _nonNullError(replacement.error); | 746 error = _nonNullError(replacement.error); |
747 stackTrace = replacement.stackTrace; | 747 stackTrace = replacement.stackTrace; |
748 } | 748 } |
749 result._completeError(error, stackTrace); | 749 result._completeError(error, stackTrace); |
750 } | 750 } |
751 | 751 |
752 /** Helper function that converts `null` to a [NullThrownError]. */ | 752 /** Helper function that converts `null` to a [NullThrownError]. */ |
753 Object _nonNullError(Object error) => | 753 Object _nonNullError(Object error) => |
754 (error != null) ? error : new NullThrownError(); | 754 (error != null) ? error : new NullThrownError(); |
OLD | NEW |