Chromium Code Reviews| 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; |
| } |
| } |