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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 bool addStream(Stream stream) { | 117 bool addStream(Stream stream) { |
118 if (!onListenReceived) _fatal("yield before stream is listened to!"); | 118 if (!onListenReceived) _fatal("yield before stream is listened to!"); |
119 // If stream is cancelled, tell caller to exit the async generator. | 119 // If stream is cancelled, tell caller to exit the async generator. |
120 if (!controller.hasListener) return true; | 120 if (!controller.hasListener) return true; |
121 isAdding = true; | 121 isAdding = true; |
122 var whenDoneAdding = | 122 var whenDoneAdding = |
123 controller.addStream(stream as Stream, cancelOnError: false); | 123 controller.addStream(stream as Stream, cancelOnError: false); |
124 whenDoneAdding.then((_) { | 124 whenDoneAdding.then((_) { |
125 isAdding = false; | 125 isAdding = false; |
126 scheduleGenerator(); | 126 scheduleGenerator(); |
| 127 if (!isScheduled) isSuspendedAtYield = true; |
127 }); | 128 }); |
128 return false; | 129 return false; |
129 } | 130 } |
130 | 131 |
131 void addError(error, stackTrace) { | 132 void addError(error, stackTrace) { |
132 if ((cancellationCompleter != null) && !cancellationCompleter.isCompleted) { | 133 if ((cancellationCompleter != null) && !cancellationCompleter.isCompleted) { |
133 // If the stream has been cancelled, complete the cancellation future | 134 // If the stream has been cancelled, complete the cancellation future |
134 // with the error. | 135 // with the error. |
135 cancellationCompleter.completeError(error, stackTrace); | 136 cancellationCompleter.completeError(error, stackTrace); |
136 return; | 137 return; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // suspended at an await. | 183 // suspended at an await. |
183 if (isSuspendedAtYield) { | 184 if (isSuspendedAtYield) { |
184 scheduleGenerator(); | 185 scheduleGenerator(); |
185 } | 186 } |
186 } | 187 } |
187 return cancellationCompleter.future; | 188 return cancellationCompleter.future; |
188 } | 189 } |
189 } | 190 } |
190 | 191 |
191 @patch void _rethrow(Object error, StackTrace stackTrace) native "Async_rethrow"
; | 192 @patch void _rethrow(Object error, StackTrace stackTrace) native "Async_rethrow"
; |
OLD | NEW |