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" hide Symbol; | 5 import "dart:_internal" hide Symbol; |
6 | 6 |
7 // Equivalent of calling FATAL from C++ code. | 7 // Equivalent of calling FATAL from C++ code. |
8 _fatal(msg) native "DartAsync_fatal"; | 8 _fatal(msg) native "DartAsync_fatal"; |
9 | 9 |
10 // We need to pass the value as first argument and leave the second and third | 10 // We need to pass the value as first argument and leave the second and third |
(...skipping 27 matching lines...) Expand all Loading... |
38 if (Zone.current == Zone.ROOT) return errorCallback; | 38 if (Zone.current == Zone.ROOT) return errorCallback; |
39 return Zone.current.registerBinaryCallback(errorCallback); | 39 return Zone.current.registerBinaryCallback(errorCallback); |
40 } | 40 } |
41 | 41 |
42 /// Registers the [thenCallback] and [errorCallback] on the given [object]. | 42 /// Registers the [thenCallback] and [errorCallback] on the given [object]. |
43 /// | 43 /// |
44 /// If [object] is not a future, then it is wrapped into one. | 44 /// If [object] is not a future, then it is wrapped into one. |
45 /// | 45 /// |
46 /// Returns the result of registering with `.then`. | 46 /// Returns the result of registering with `.then`. |
47 Future _awaitHelper( | 47 Future _awaitHelper( |
48 var object, | 48 var object, Function thenCallback, Function errorCallback, var awaiter) { |
49 Function thenCallback, | |
50 Function errorCallback, | |
51 var awaiter) { | |
52 if (object is! Future) { | 49 if (object is! Future) { |
53 object = new _Future().._setValue(object); | 50 object = new _Future().._setValue(object); |
54 } else if (object is! _Future) { | 51 } else if (object is! _Future) { |
55 return object.then(thenCallback, onError: errorCallback); | 52 return object.then(thenCallback, onError: errorCallback); |
56 } | 53 } |
57 // `object` is a `_Future`. | 54 // `object` is a `_Future`. |
58 // | 55 // |
59 // Since the callbacks have been registered in the current zone (see | 56 // Since the callbacks have been registered in the current zone (see |
60 // [_asyncThenWrapperHelper] and [_asyncErrorWrapperHelper]), we can avoid | 57 // [_asyncThenWrapperHelper] and [_asyncErrorWrapperHelper]), we can avoid |
61 // another registration and directly invoke the no-zone-registration `.then`. | 58 // another registration and directly invoke the no-zone-registration `.then`. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 close() { | 169 close() { |
173 if ((cancellationCompleter != null) && !cancellationCompleter.isCompleted) { | 170 if ((cancellationCompleter != null) && !cancellationCompleter.isCompleted) { |
174 // If the stream has been cancelled, complete the cancellation future | 171 // If the stream has been cancelled, complete the cancellation future |
175 // with the error. | 172 // with the error. |
176 cancellationCompleter.complete(); | 173 cancellationCompleter.complete(); |
177 } | 174 } |
178 controller.close(); | 175 controller.close(); |
179 } | 176 } |
180 | 177 |
181 _AsyncStarStreamController(this.asyncStarBody) { | 178 _AsyncStarStreamController(this.asyncStarBody) { |
182 controller = new StreamController(onListen: this.onListen, | 179 controller = new StreamController( |
183 onResume: this.onResume, | 180 onListen: this.onListen, |
184 onCancel: this.onCancel); | 181 onResume: this.onResume, |
| 182 onCancel: this.onCancel); |
185 } | 183 } |
186 | 184 |
187 onListen() { | 185 onListen() { |
188 assert(!onListenReceived); | 186 assert(!onListenReceived); |
189 onListenReceived = true; | 187 onListenReceived = true; |
190 scheduleGenerator(); | 188 scheduleGenerator(); |
191 } | 189 } |
192 | 190 |
193 onResume() { | 191 onResume() { |
194 if (isSuspendedAtYield) { | 192 if (isSuspendedAtYield) { |
(...skipping 11 matching lines...) Expand all Loading... |
206 // Cancellation does not affect an async generator that is | 204 // Cancellation does not affect an async generator that is |
207 // suspended at an await. | 205 // suspended at an await. |
208 if (isSuspendedAtYield) { | 206 if (isSuspendedAtYield) { |
209 scheduleGenerator(); | 207 scheduleGenerator(); |
210 } | 208 } |
211 } | 209 } |
212 return cancellationCompleter.future; | 210 return cancellationCompleter.future; |
213 } | 211 } |
214 } | 212 } |
215 | 213 |
216 @patch void _rethrow(Object error, StackTrace stackTrace) native "Async_rethrow"
; | 214 @patch |
| 215 void _rethrow(Object error, StackTrace stackTrace) native "Async_rethrow"; |
217 | 216 |
218 @patch class _Future<T> { | 217 @patch |
| 218 class _Future<T> { |
219 /// The closure implementing the async[*]-body that is `await`ing this future. | 219 /// The closure implementing the async[*]-body that is `await`ing this future. |
220 Function _awaiter; | 220 Function _awaiter; |
221 } | 221 } |
222 | 222 |
223 @patch class _StreamImpl<T> { | 223 @patch |
| 224 class _StreamImpl<T> { |
224 /// The closure implementing the async[*]-body that is `await`ing this future. | 225 /// The closure implementing the async[*]-body that is `await`ing this future. |
225 Function _awaiter; | 226 Function _awaiter; |
| 227 |
226 /// The closure implementing the async-generator body that is creating events | 228 /// The closure implementing the async-generator body that is creating events |
227 /// for this stream. | 229 /// for this stream. |
228 Function _generator; | 230 Function _generator; |
229 } | 231 } |
230 | 232 |
231 /// Returns a [StackTrace] object containing the synchronous prefix for this | 233 /// Returns a [StackTrace] object containing the synchronous prefix for this |
232 /// asynchronous method. | 234 /// asynchronous method. |
233 Object _asyncStackTraceHelper() | 235 Object _asyncStackTraceHelper() native "StackTrace_asyncStackTraceHelper"; |
234 native "StackTrace_asyncStackTraceHelper"; | |
235 | 236 |
236 void _clearAsyncThreadStackTrace() | 237 void _clearAsyncThreadStackTrace() |
237 native "StackTrace_clearAsyncThreadStackTrace"; | 238 native "StackTrace_clearAsyncThreadStackTrace"; |
238 | 239 |
239 void _setAsyncThreadStackTrace(StackTrace stackTrace) native | 240 void _setAsyncThreadStackTrace(StackTrace stackTrace) |
240 "StackTrace_setAsyncThreadStackTrace"; | 241 native "StackTrace_setAsyncThreadStackTrace"; |
OLD | NEW |