| 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, Function thenCallback, Function errorCallback, var awaiter) { | 48 var object, |
| 49 Function thenCallback, |
| 50 Function errorCallback, |
| 51 var awaiter) { |
| 49 if (object is! Future) { | 52 if (object is! Future) { |
| 50 object = new _Future().._setValue(object); | 53 object = new _Future().._setValue(object); |
| 51 } else if (object is! _Future) { | 54 } else if (object is! _Future) { |
| 52 return object.then(thenCallback, onError: errorCallback); | 55 return object.then(thenCallback, onError: errorCallback); |
| 53 } | 56 } |
| 54 // `object` is a `_Future`. | 57 // `object` is a `_Future`. |
| 55 // | 58 // |
| 56 // Since the callbacks have been registered in the current zone (see | 59 // Since the callbacks have been registered in the current zone (see |
| 57 // [_asyncThenWrapperHelper] and [_asyncErrorWrapperHelper]), we can avoid | 60 // [_asyncThenWrapperHelper] and [_asyncErrorWrapperHelper]), we can avoid |
| 58 // another registration and directly invoke the no-zone-registration `.then`. | 61 // another registration and directly invoke the no-zone-registration `.then`. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 close() { | 172 close() { |
| 170 if ((cancellationCompleter != null) && !cancellationCompleter.isCompleted) { | 173 if ((cancellationCompleter != null) && !cancellationCompleter.isCompleted) { |
| 171 // If the stream has been cancelled, complete the cancellation future | 174 // If the stream has been cancelled, complete the cancellation future |
| 172 // with the error. | 175 // with the error. |
| 173 cancellationCompleter.complete(); | 176 cancellationCompleter.complete(); |
| 174 } | 177 } |
| 175 controller.close(); | 178 controller.close(); |
| 176 } | 179 } |
| 177 | 180 |
| 178 _AsyncStarStreamController(this.asyncStarBody) { | 181 _AsyncStarStreamController(this.asyncStarBody) { |
| 179 controller = new StreamController( | 182 controller = new StreamController(onListen: this.onListen, |
| 180 onListen: this.onListen, | 183 onResume: this.onResume, |
| 181 onResume: this.onResume, | 184 onCancel: this.onCancel); |
| 182 onCancel: this.onCancel); | |
| 183 } | 185 } |
| 184 | 186 |
| 185 onListen() { | 187 onListen() { |
| 186 assert(!onListenReceived); | 188 assert(!onListenReceived); |
| 187 onListenReceived = true; | 189 onListenReceived = true; |
| 188 scheduleGenerator(); | 190 scheduleGenerator(); |
| 189 } | 191 } |
| 190 | 192 |
| 191 onResume() { | 193 onResume() { |
| 192 if (isSuspendedAtYield) { | 194 if (isSuspendedAtYield) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 204 // Cancellation does not affect an async generator that is | 206 // Cancellation does not affect an async generator that is |
| 205 // suspended at an await. | 207 // suspended at an await. |
| 206 if (isSuspendedAtYield) { | 208 if (isSuspendedAtYield) { |
| 207 scheduleGenerator(); | 209 scheduleGenerator(); |
| 208 } | 210 } |
| 209 } | 211 } |
| 210 return cancellationCompleter.future; | 212 return cancellationCompleter.future; |
| 211 } | 213 } |
| 212 } | 214 } |
| 213 | 215 |
| 214 @patch | 216 @patch void _rethrow(Object error, StackTrace stackTrace) native "Async_rethrow"
; |
| 215 void _rethrow(Object error, StackTrace stackTrace) native "Async_rethrow"; | |
| 216 | 217 |
| 217 @patch | 218 @patch class _Future<T> { |
| 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 | 223 @patch class _StreamImpl<T> { |
| 224 class _StreamImpl<T> { | |
| 225 /// The closure implementing the async[*]-body that is `await`ing this future. | 224 /// The closure implementing the async[*]-body that is `await`ing this future. |
| 226 Function _awaiter; | 225 Function _awaiter; |
| 227 | |
| 228 /// The closure implementing the async-generator body that is creating events | 226 /// The closure implementing the async-generator body that is creating events |
| 229 /// for this stream. | 227 /// for this stream. |
| 230 Function _generator; | 228 Function _generator; |
| 231 } | 229 } |
| 232 | 230 |
| 233 /// Returns a [StackTrace] object containing the synchronous prefix for this | 231 /// Returns a [StackTrace] object containing the synchronous prefix for this |
| 234 /// asynchronous method. | 232 /// asynchronous method. |
| 235 Object _asyncStackTraceHelper() native "StackTrace_asyncStackTraceHelper"; | 233 Object _asyncStackTraceHelper() |
| 234 native "StackTrace_asyncStackTraceHelper"; |
| 236 | 235 |
| 237 void _clearAsyncThreadStackTrace() | 236 void _clearAsyncThreadStackTrace() |
| 238 native "StackTrace_clearAsyncThreadStackTrace"; | 237 native "StackTrace_clearAsyncThreadStackTrace"; |
| 239 | 238 |
| 240 void _setAsyncThreadStackTrace(StackTrace stackTrace) | 239 void _setAsyncThreadStackTrace(StackTrace stackTrace) native |
| 241 native "StackTrace_setAsyncThreadStackTrace"; | 240 "StackTrace_setAsyncThreadStackTrace"; |
| OLD | NEW |