Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Unified Diff: sdk/lib/_internal/js_runtime/lib/async_patch.dart

Issue 1677063003: More tests for async* functions (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add another test. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/js_runtime/lib/async_patch.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/async_patch.dart b/sdk/lib/_internal/js_runtime/lib/async_patch.dart
index 4d91d7948c31ceb37b515b2a04f3641619b5f5cb..789ca256f45980a723db3145270aafbb29abf9ca 100644
--- a/sdk/lib/_internal/js_runtime/lib/async_patch.dart
+++ b/sdk/lib/_internal/js_runtime/lib/async_patch.dart
@@ -255,10 +255,13 @@ _WrappedAsyncBody _wrapJsFunctionForAsync(dynamic /* js function */ function) {
/// is done, schedules [asyncBody] again.
///
/// If the async* function wants to do an await it calls this function with
-/// [object] not and [IterationMarker].
+/// [object] not an [IterationMarker].
///
/// If [object] is not a [Future], it is wrapped in a `Future.value`.
/// The [asyncBody] is called on completion of the future (see [asyncHelper].
+/// If the stream has been canceled in the meantime, the body is
+/// called with [async_error_codes.STREAM_WAS_CANCELED] once the future
+/// completes.
Lasse Reichstein Nielsen 2016/02/08 17:44:24 That's not correct. Canceled async* functions must
Lasse Reichstein Nielsen 2016/02/08 20:54:44 (or maybe I'm not understanding exactly what happe
floitsch 2016/02/09 16:56:34 My fault. I reverted these changes.
void _asyncStarHelper(dynamic object,
dynamic /* int | _WrappedAsyncBody */ bodyFunctionOrErrorCode,
_AsyncStarStreamController controller) {
@@ -322,7 +325,17 @@ void _asyncStarHelper(dynamic object,
}
}
- _awaitOnObject(object, bodyFunctionOrErrorCode);
+ // Executes the body-function, unless the subscription was canceled while
+ // waiting for the object.
+ void runBodyOrCancel(int errorCode, dynamic result) {
+ if (controller.isCanceled) {
+ bodyFunctionOrErrorCode(async_error_codes.STREAM_WAS_CANCELED, null);
+ return;
+ }
+ bodyFunctionOrErrorCode(errorCode, result);
+ }
+
+ _awaitOnObject(object, runBodyOrCancel);
}
Stream _streamOfController(_AsyncStarStreamController controller) {

Powered by Google App Engine
This is Rietveld 408576698