| 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 class _SupercedeEntry<T> { | 7 class _SupercedeEntry<T> { |
| 8 final _SupercedeStream stream; | 8 final _SupercedeStream stream; |
| 9 Stream<T> source; | 9 Stream<T> source; |
| 10 StreamSubscription subscription = null; | 10 StreamSubscription subscription = null; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 * activated. | 152 * activated. |
| 153 * | 153 * |
| 154 * If the source completes, the entry is removed from [stream]. | 154 * If the source completes, the entry is removed from [stream]. |
| 155 */ | 155 */ |
| 156 class _CycleEntry<T> { | 156 class _CycleEntry<T> { |
| 157 final _CyclicScheduleStream stream; | 157 final _CyclicScheduleStream stream; |
| 158 /** A single source stream for the [_CyclicScheduleStream]. */ | 158 /** A single source stream for the [_CyclicScheduleStream]. */ |
| 159 Stream source; | 159 Stream source; |
| 160 /** The active subscription, if any. */ | 160 /** The active subscription, if any. */ |
| 161 StreamSubscription subscription = null; | 161 StreamSubscription subscription = null; |
| 162 /** Whether the subscription is currently paused. */ |
| 163 bool isPaused = false; |
| 162 /** Next entry in a linked list of entries. */ | 164 /** Next entry in a linked list of entries. */ |
| 163 _CycleEntry next; | 165 _CycleEntry next; |
| 164 | 166 |
| 165 _CycleEntry(this.stream, this.source); | 167 _CycleEntry(this.stream, this.source); |
| 166 | 168 |
| 167 void cancel() { | 169 void cancel() { |
| 168 // This method may be called event if this entry has never been activated. | 170 // This method may be called even if this entry has never been activated. |
| 169 if (subscription != null) { | 171 if (subscription != null) { |
| 170 subscription.cancel(); | 172 subscription.cancel(); |
| 171 subscription = null; | 173 subscription = null; |
| 174 isPaused = false; |
| 172 } | 175 } |
| 173 } | 176 } |
| 174 | 177 |
| 175 void pause() { | 178 void pause() { |
| 176 ensureSubscribed(); | 179 ensureSubscribed(); |
| 177 if (!subscription.isPaused) { | 180 if (!isPaused) { |
| 178 subscription.pause(); | 181 subscription.pause(); |
| 182 isPaused = true; |
| 179 } | 183 } |
| 180 } | 184 } |
| 181 | 185 |
| 182 void activate() { | 186 void activate() { |
| 183 ensureSubscribed(); | 187 ensureSubscribed(); |
| 184 if (subscription.isPaused) { | 188 if (isPaused) { |
| 189 isPaused = false; |
| 185 subscription.resume(); | 190 subscription.resume(); |
| 186 } | 191 } |
| 187 } | 192 } |
| 188 | 193 |
| 189 void ensureSubscribed() { | 194 void ensureSubscribed() { |
| 190 if (subscription == null) { | 195 if (subscription == null) { |
| 191 subscription = | 196 subscription = |
| 192 source.listen(stream._onData, | 197 source.listen(stream._onData, |
| 193 onError: stream._signalError, | 198 onError: stream._signalError, |
| 194 onDone: stream._onDone); | 199 onDone: stream._onDone); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 if (_currentEntry.next == null) { | 278 if (_currentEntry.next == null) { |
| 274 _close(); | 279 _close(); |
| 275 _currentEntry = _lastEntry = null; | 280 _currentEntry = _lastEntry = null; |
| 276 } else { | 281 } else { |
| 277 // Remove the current entry from the list now that it's complete. | 282 // Remove the current entry from the list now that it's complete. |
| 278 _currentEntry = _currentEntry.next; | 283 _currentEntry = _currentEntry.next; |
| 279 _currentEntry.activate(); | 284 _currentEntry.activate(); |
| 280 } | 285 } |
| 281 } | 286 } |
| 282 } | 287 } |
| OLD | NEW |