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

Side by Side Diff: sdk/lib/async/future.dart

Issue 1606543005: Update Stream.listen doc and use ?? in some places. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comment Created 4 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
« no previous file with comments | « CHANGELOG.md ('k') | sdk/lib/async/stream.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 (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
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
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();
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | sdk/lib/async/stream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698