| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library _js_helper; | 5 library _js_helper; |
| 6 | 6 |
| 7 import 'dart:_async_await_error_codes' as async_error_codes; | 7 import 'dart:_async_await_error_codes' as async_error_codes; |
| 8 | 8 |
| 9 import 'dart:_js_embedded_names' show | 9 import 'dart:_js_embedded_names' show |
| 10 DEFERRED_LIBRARY_URIS, | 10 DEFERRED_LIBRARY_URIS, |
| (...skipping 3734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3745 /// A wrapper around a [StreamController] that remembers if that controller | 3745 /// A wrapper around a [StreamController] that remembers if that controller |
| 3746 /// got a cancel. | 3746 /// got a cancel. |
| 3747 /// | 3747 /// |
| 3748 /// Also has a subSubscription that when not null will provide events for the | 3748 /// Also has a subSubscription that when not null will provide events for the |
| 3749 /// stream, and will be paused and resumed along with this controller. | 3749 /// stream, and will be paused and resumed along with this controller. |
| 3750 class AsyncStarStreamController { | 3750 class AsyncStarStreamController { |
| 3751 StreamController controller; | 3751 StreamController controller; |
| 3752 Stream get stream => controller.stream; | 3752 Stream get stream => controller.stream; |
| 3753 bool stopRunning = false; | 3753 bool stopRunning = false; |
| 3754 bool isAdding = false; | 3754 bool isAdding = false; |
| 3755 bool get isPaused => controller.isPaused; | 3755 bool isPaused = false; |
| 3756 add(event) => controller.add(event); | 3756 add(event) => controller.add(event); |
| 3757 addStream(Stream stream) { | 3757 addStream(Stream stream) { |
| 3758 return controller.addStream(stream, cancelOnError: false); | 3758 return controller.addStream(stream, cancelOnError: false); |
| 3759 } | 3759 } |
| 3760 addError(error, stackTrace) => controller.addError(error, stackTrace); | 3760 addError(error, stackTrace) => controller.addError(error, stackTrace); |
| 3761 close() => controller.close(); | 3761 close() => controller.close(); |
| 3762 | 3762 |
| 3763 AsyncStarStreamController(body) { | 3763 AsyncStarStreamController(body) { |
| 3764 controller = new StreamController( | 3764 controller = new StreamController( |
| 3765 onListen: () { | 3765 onListen: () { |
| 3766 scheduleMicrotask(() { | 3766 scheduleMicrotask(() { |
| 3767 Function wrapped = _wrapJsFunctionForAsync(body, | 3767 Function wrapped = _wrapJsFunctionForAsync(body, |
| 3768 async_error_codes.SUCCESS); | 3768 async_error_codes.SUCCESS); |
| 3769 wrapped(null); | 3769 wrapped(null); |
| 3770 }); | 3770 }); |
| 3771 }, | 3771 }, |
| 3772 onResume: () { | 3772 onPause: () { |
| 3773 isPaused = true; |
| 3774 }, onResume: () { |
| 3775 isPaused = false; |
| 3773 if (!isAdding) { | 3776 if (!isAdding) { |
| 3774 asyncStarHelper(null, body, this); | 3777 asyncStarHelper(null, body, this); |
| 3775 } | 3778 } |
| 3776 }, onCancel: () { | 3779 }, onCancel: () { |
| 3777 stopRunning = true; | 3780 stopRunning = true; |
| 3781 if (isPaused) asyncStarHelper(null, body, this); |
| 3778 }); | 3782 }); |
| 3779 } | 3783 } |
| 3780 } | 3784 } |
| 3781 | 3785 |
| 3782 makeAsyncStarController(body) { | 3786 makeAsyncStarController(body) { |
| 3783 return new AsyncStarStreamController(body); | 3787 return new AsyncStarStreamController(body); |
| 3784 } | 3788 } |
| 3785 | 3789 |
| 3786 class IterationMarker { | 3790 class IterationMarker { |
| 3787 static const YIELD_SINGLE = 0; | 3791 static const YIELD_SINGLE = 0; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3881 // This is a function that will return a helper function that does the | 3885 // This is a function that will return a helper function that does the |
| 3882 // iteration of the sync*. | 3886 // iteration of the sync*. |
| 3883 // | 3887 // |
| 3884 // Each invocation should give a body with fresh state. | 3888 // Each invocation should give a body with fresh state. |
| 3885 final dynamic /* js function */ _outerHelper; | 3889 final dynamic /* js function */ _outerHelper; |
| 3886 | 3890 |
| 3887 SyncStarIterable(this._outerHelper); | 3891 SyncStarIterable(this._outerHelper); |
| 3888 | 3892 |
| 3889 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper)); | 3893 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper)); |
| 3890 } | 3894 } |
| OLD | NEW |