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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 * Completes the future synchronously. | 618 * Completes the future synchronously. |
619 * | 619 * |
620 * This constructor should be avoided unless the completion of the future is | 620 * This constructor should be avoided unless the completion of the future is |
621 * known to be the final result of another asynchronous operation. If in doubt | 621 * known to be the final result of another asynchronous operation. If in doubt |
622 * use the default [Completer] constructor. | 622 * use the default [Completer] constructor. |
623 * | 623 * |
624 * Using an normal, asynchronous, completer will never give the wrong | 624 * Using an normal, asynchronous, completer will never give the wrong |
625 * behavior, but using a synchronous completer incorrectly can cause | 625 * behavior, but using a synchronous completer incorrectly can cause |
626 * otherwise correct programs to break. | 626 * otherwise correct programs to break. |
627 * | 627 * |
628 * An asynchronous completer is only intended for optimizing event | 628 * A synchronous completer is only intended for optimizing event |
629 * propagation when one asynchronous event immediately triggers another. | 629 * propagation when one asynchronous event immediately triggers another. |
630 * It should not be used unless the calls to [complete] and [completeError] | 630 * It should not be used unless the calls to [complete] and [completeError] |
631 * are guaranteed to occur in places where it won't break `Future` invariants. | 631 * are guaranteed to occur in places where it won't break `Future` invariants. |
632 * | 632 * |
633 * Completing synchronously means that the completer's future will be | 633 * Completing synchronously means that the completer's future will be |
634 * completed immediately when calling the [complete] or [completeError] | 634 * completed immediately when calling the [complete] or [completeError] |
635 * method on a synchronous completer, which also calls any callbacks | 635 * method on a synchronous completer, which also calls any callbacks |
636 * registered on that future. | 636 * registered on that future. |
637 * | 637 * |
638 * Completing synchronously must not break the rule that when you add a | 638 * Completing synchronously must not break the rule that when you add a |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 if (replacement != null) { | 720 if (replacement != null) { |
721 error = _nonNullError(replacement.error); | 721 error = _nonNullError(replacement.error); |
722 stackTrace = replacement.stackTrace; | 722 stackTrace = replacement.stackTrace; |
723 } | 723 } |
724 result._completeError(error, stackTrace); | 724 result._completeError(error, stackTrace); |
725 } | 725 } |
726 | 726 |
727 /** Helper function that converts `null` to a [NullThrownError]. */ | 727 /** Helper function that converts `null` to a [NullThrownError]. */ |
728 Object _nonNullError(Object error) => | 728 Object _nonNullError(Object error) => |
729 (error != null) ? error : new NullThrownError(); | 729 (error != null) ? error : new NullThrownError(); |
OLD | NEW |