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

Unified Diff: runtime/lib/core_patch.dart

Issue 1014273003: Make await for cancel the stream when breaking out of the loop (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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 | runtime/vm/ast.h » ('j') | runtime/vm/parser.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/core_patch.dart
===================================================================
--- runtime/lib/core_patch.dart (revision 44677)
+++ runtime/lib/core_patch.dart (working copy)
@@ -36,6 +36,7 @@
bool isAdding = false;
bool onListenReceived = false;
bool isScheduled = false;
+ Completer cancellationCompleter = null;
Stream get stream => controller.stream;
@@ -93,6 +94,13 @@
}
void addError(error, stackTrace) {
+ if ((cancellationCompleter != null &&
regis 2015/03/24 23:46:27 Redundant pair of parenthesis
hausner 2015/03/24 23:57:29 Done.
+ !cancellationCompleter.isCompleted)) {
+ // If the stream has been cancelled, complete the cancellation future
+ // with the error.
+ cancellationCompleter.completeError(error, stackTrace);
+ return;
+ }
// If stream is cancelled, tell caller to exit the async generator.
if (!controller.hasListener) return;
controller.addError(error, stackTrace);
@@ -103,6 +111,12 @@
}
close() {
+ if ((cancellationCompleter != null) &&
regis 2015/03/24 23:46:27 ditto
hausner 2015/03/24 23:57:29 This one actually had the closing paren in the rig
+ !cancellationCompleter.isCompleted) {
+ // If the stream has been cancelled, complete the cancellation future
+ // with the error.
+ cancellationCompleter.complete();
+ }
controller.close();
}
@@ -123,7 +137,14 @@
}
onCancel() {
- scheduleGenerator();
+ if (controller.isClosed) {
+ return null;
+ }
+ if (cancellationCompleter == null) {
+ cancellationCompleter = new Completer();
+ scheduleGenerator();
+ }
+ return cancellationCompleter.future;
}
}
« no previous file with comments | « no previous file | runtime/vm/ast.h » ('j') | runtime/vm/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698