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

Unified Diff: sdk/lib/_internal/compiler/js_lib/js_helper.dart

Issue 1026743002: Fix cancel behaviour of async* in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review Created 5 years, 9 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
« no previous file with comments | « no previous file | tests/language/async_star_cancel_and_throw_in_finally_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/js_lib/js_helper.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/js_helper.dart b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
index e585b8c0211ee0b5e586b884937ca992adfaf093..3b02cf27c88f0c8dd543bde9707c37ae274c37c1 100644
--- a/sdk/lib/_internal/compiler/js_lib/js_helper.dart
+++ b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
@@ -3685,18 +3685,28 @@ void asyncStarHelper(dynamic object,
AsyncStarStreamController controller) {
if (identical(bodyFunctionOrErrorCode, async_error_codes.SUCCESS)) {
// This happens on return from the async* function.
- controller.close();
+ if (controller.cancelationCompleter != null) {
+ controller.cancelationCompleter.complete();
+ } else {
+ controller.close();
+ }
return;
} else if (identical(bodyFunctionOrErrorCode, async_error_codes.ERROR)) {
// The error is a js-error.
- controller.addError(unwrapException(object),
- getTraceFromException(object));
- controller.close();
+ if (controller.cancelationCompleter != null) {
+ controller.cancelationCompleter.completeError(
+ unwrapException(object),
+ getTraceFromException(object));
+ } else {
+ controller.addError(unwrapException(object),
+ getTraceFromException(object));
+ controller.close();
+ }
return;
}
if (object is IterationMarker) {
- if (controller.stopRunning) {
+ if (controller.cancelationCompleter != null) {
_wrapJsFunctionForAsync(bodyFunctionOrErrorCode,
async_error_codes.STREAM_WAS_CANCELED)(null);
return;
@@ -3753,7 +3763,8 @@ Stream streamOfController(AsyncStarStreamController controller) {
class AsyncStarStreamController {
StreamController controller;
Stream get stream => controller.stream;
- bool stopRunning = false;
+ Completer cancelationCompleter = null;
+ bool get isCanceled => cancelationCompleter != null;
bool isAdding = false;
bool isPaused = false;
add(event) => controller.add(event);
@@ -3780,8 +3791,12 @@ class AsyncStarStreamController {
asyncStarHelper(null, body, this);
}
}, onCancel: () {
- stopRunning = true;
- if (isPaused) asyncStarHelper(null, body, this);
+ if (!controller.isClosed) {
+ cancelationCompleter = new Completer();
+ if (isPaused) asyncStarHelper(null, body, this);
+
+ return cancelationCompleter.future;
+ }
});
}
}
« no previous file with comments | « no previous file | tests/language/async_star_cancel_and_throw_in_finally_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698