Chromium Code Reviews| 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 // Controller for creating and adding events to a stream. | 8 // Controller for creating and adding events to a stream. |
| 9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
| 10 | 10 |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 _StreamControllerAddStreamState<T> addState = | 702 _StreamControllerAddStreamState<T> addState = |
| 703 _varData as Object /*=_StreamControllerAddStreamState<T>*/; | 703 _varData as Object /*=_StreamControllerAddStreamState<T>*/; |
| 704 result = addState.cancel(); | 704 result = addState.cancel(); |
| 705 } | 705 } |
| 706 _varData = null; | 706 _varData = null; |
| 707 _state = | 707 _state = |
| 708 (_state & ~(_STATE_SUBSCRIBED | _STATE_ADDSTREAM)) | _STATE_CANCELED; | 708 (_state & ~(_STATE_SUBSCRIBED | _STATE_ADDSTREAM)) | _STATE_CANCELED; |
| 709 | 709 |
| 710 if (onCancel != null) { | 710 if (onCancel != null) { |
| 711 if (result == null) { | 711 if (result == null) { |
| 712 // Only introduce a future if one is needed. | 712 // Introduce a future if none was returned. |
| 713 // If _onCancel returns null, no future is needed. | |
| 714 try { | 713 try { |
| 715 result = onCancel(); | 714 result = onCancel() ?? new Future.value(null); |
|
Lasse Reichstein Nielsen
2016/08/01 15:23:26
Use `Future._nullFuture`.
floitsch
2016/08/01 21:00:37
Moved the 'Future._nullFuture' to the `cancel` fun
| |
| 716 } catch (e, s) { | 715 } catch (e, s) { |
| 717 // Return the error in the returned future. | 716 // Return the error in the returned future. |
| 718 // Complete it asynchronously, so there is time for a listener | 717 // Complete it asynchronously, so there is time for a listener |
| 719 // to handle the error. | 718 // to handle the error. |
| 720 result = new _Future().._asyncCompleteError(e, s); | 719 result = new _Future().._asyncCompleteError(e, s); |
| 721 } | 720 } |
| 722 } else { | 721 } else { |
| 723 // Simpler case when we already know that we will return a future. | 722 // Simpler case when we already know that we will return a future. |
| 724 result = result.whenComplete(onCancel); | 723 result = result.whenComplete(onCancel); |
| 725 } | 724 } |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 939 _StreamControllerAddStreamState(_StreamController<T> controller, | 938 _StreamControllerAddStreamState(_StreamController<T> controller, |
| 940 this.varData, | 939 this.varData, |
| 941 Stream source, | 940 Stream source, |
| 942 bool cancelOnError) | 941 bool cancelOnError) |
| 943 : super(controller, source, cancelOnError) { | 942 : super(controller, source, cancelOnError) { |
| 944 if (controller.isPaused) { | 943 if (controller.isPaused) { |
| 945 addSubscription.pause(); | 944 addSubscription.pause(); |
| 946 } | 945 } |
| 947 } | 946 } |
| 948 } | 947 } |
| OLD | NEW |