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

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

Issue 2562703002: Add `FutureOr<T>` class to `dart:async`. (Closed)
Patch Set: Reword. Created 4 years 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 | « no previous file | no next file » | 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 /// The union of `Future<T>` and `T`.
Lasse Reichstein Nielsen 2016/12/08 15:14:00 I would save the "union" word to the advanced sect
floitsch 2016/12/08 16:23:59 That wording doesn't work for me. If read the wron
8 ///
9 /// This is a magic class that is recognized by the Dart tools. It is
Lasse Reichstein Nielsen 2016/12/08 15:14:00 I wouldn't actually use the word "magic" in writin
floitsch 2016/12/08 16:23:59 Changed. PTAL.
10 /// used in places where functions accept or return a `Future<T>` or a `T`.
11 ///
12 /// This class can not be implemented or extended.
Lasse Reichstein Nielsen 2016/12/08 15:14:00 or mixed in. The spec language is (e.g.):
Brian Wilkerson 2016/12/08 15:25:46 nit: "can not" --> "cannot" nit: or mixed in? (may
floitsch 2016/12/08 16:23:59 Done.
13 ///
14 /// Note: the `FutureOr<T>` type is interpreted as `dynamic` in non strong-mode.
15 ///
16 /// # Examples
17 /// ``` dart
18 /// // The `Future<T>.then` function takes a callback [f] that returns either
19 /// // an `S` or a `Future<S>`.
20 /// Future<S> then<S>(FutureOr<S> f(T x), ...);
21 ///
22 /// // `Completer<T>.complete` takes either a `T` or `Future<T>`.
23 /// void complete(FutureOr<T> value);
24 /// ```
25 ///
26 /// # Advanced
27 /// Since `FutureOr<Object>` is the union of `Future<Object>` and `Object`, it
Lasse Reichstein Nielsen 2016/12/08 15:14:00 "the union" isn't defined anywhere, so it's not cl
floitsch 2016/12/08 16:23:59 Done.
28 /// is equivalent to `Object`, because `Future<Object>` is a subtype of
29 /// `Object`.
30 ///
31 /// As a corollary, `FutureOr<Object>` is equivalent to
32 /// `FutureOr<FutureOr<Object>>`.
Lasse Reichstein Nielsen 2016/12/08 15:14:00 (and equivalent to Object) The more interesting e
floitsch 2016/12/08 16:23:59 Done.
33 class FutureOr<T> {
34 // Private constructor, so that it is not subclassable and instantiable.
Lasse Reichstein Nielsen 2016/12/08 15:14:00 or mixin'able, as if that was a word. For even mo
floitsch 2016/12/08 16:23:59 Done.
35 FutureOr._();
36 }
37
7 /** 38 /**
8 * An object representing a delayed computation. 39 * An object representing a delayed computation.
9 * 40 *
10 * A [Future] is used to represent a potential value, or error, 41 * A [Future] is used to represent a potential value, or error,
11 * that will be available at some time in the future. 42 * that will be available at some time in the future.
12 * Receivers of a [Future] can register callbacks 43 * Receivers of a [Future] can register callbacks
13 * that handle the value or error once it is available. 44 * that handle the value or error once it is available.
14 * For example: 45 * For example:
15 * 46 *
16 * Future<int> future = getFuture(); 47 * Future<int> future = getFuture();
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 if (replacement != null) { 811 if (replacement != null) {
781 error = _nonNullError(replacement.error); 812 error = _nonNullError(replacement.error);
782 stackTrace = replacement.stackTrace; 813 stackTrace = replacement.stackTrace;
783 } 814 }
784 result._completeError(error, stackTrace); 815 result._completeError(error, stackTrace);
785 } 816 }
786 817
787 /** Helper function that converts `null` to a [NullThrownError]. */ 818 /** Helper function that converts `null` to a [NullThrownError]. */
788 Object _nonNullError(Object error) => 819 Object _nonNullError(Object error) =>
789 (error != null) ? error : new NullThrownError(); 820 (error != null) ? error : new NullThrownError();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698