| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import "dart:_internal"; | 5 import "dart:_internal"; |
| 6 | 6 |
| 7 // We need to pass the value as first argument and leave the second and third | 7 // We need to pass the value as first argument and leave the second and third |
| 8 // arguments empty (used for error handling). | 8 // arguments empty (used for error handling). |
| 9 // See vm/ast_transformer.cc for usage. | 9 // See vm/ast_transformer.cc for usage. |
| 10 Function _asyncThenWrapperHelper(continuation) { | 10 Function _asyncThenWrapperHelper(continuation) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 79 } |
| 80 | 80 |
| 81 void scheduleGenerator() { | 81 void scheduleGenerator() { |
| 82 if (isScheduled || controller.isPaused || isAdding) { | 82 if (isScheduled || controller.isPaused || isAdding) { |
| 83 return; | 83 return; |
| 84 } | 84 } |
| 85 isScheduled = true; | 85 isScheduled = true; |
| 86 scheduleMicrotask(runBody); | 86 scheduleMicrotask(runBody); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Adds element to steam, returns true if the caller should terminate | 89 // Adds element to stream, returns true if the caller should terminate |
| 90 // execution of the generator. | 90 // execution of the generator. |
| 91 // | 91 // |
| 92 // TODO(hausner): Per spec, the generator should be suspended before | 92 // TODO(hausner): Per spec, the generator should be suspended before |
| 93 // exiting when the stream is closed. We could add a getter like this: | 93 // exiting when the stream is closed. We could add a getter like this: |
| 94 // get isCancelled => controller.hasListener; | 94 // get isCancelled => controller.hasListener; |
| 95 // The generator would translate a 'yield e' statement to | 95 // The generator would translate a 'yield e' statement to |
| 96 // controller.add(e); | 96 // controller.add(e); |
| 97 // suspend; | 97 // suspend; |
| 98 // if (controller.isCancelled) return; | 98 // if (controller.isCancelled) return; |
| 99 bool add(event) { | 99 bool add(event) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 scheduleGenerator(); | 170 scheduleGenerator(); |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 onCancel() { | 174 onCancel() { |
| 175 if (controller.isClosed) { | 175 if (controller.isClosed) { |
| 176 return null; | 176 return null; |
| 177 } | 177 } |
| 178 if (cancellationCompleter == null) { | 178 if (cancellationCompleter == null) { |
| 179 cancellationCompleter = new Completer(); | 179 cancellationCompleter = new Completer(); |
| 180 scheduleGenerator(); | 180 // Only resume the generator if it is suspended at a yield. |
| 181 // Cancellation does not affect an async generator that is |
| 182 // suspended at an await. |
| 183 if (isSuspendedAtYield) { |
| 184 scheduleGenerator(); |
| 185 } |
| 181 } | 186 } |
| 182 return cancellationCompleter.future; | 187 return cancellationCompleter.future; |
| 183 } | 188 } |
| 184 } | 189 } |
| 185 | 190 |
| 186 patch void _rethrow(Object error, StackTrace stackTrace) native "Async_rethrow"; | 191 patch void _rethrow(Object error, StackTrace stackTrace) native "Async_rethrow"; |
| OLD | NEW |