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

Unified Diff: sdk/lib/isolate/isolate.dart

Issue 2555493003: Let `Isolate.errors` close on isolate exit. (Closed)
Patch Set: Created 4 years 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/isolate/isolate_errors_test.dart » ('j') | tests/isolate/isolate_errors_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/isolate/isolate.dart
diff --git a/sdk/lib/isolate/isolate.dart b/sdk/lib/isolate/isolate.dart
index 77b40c07a13e4e3c39159738e7d713a548ea8f03..ef561b36729b06e464e2ab4140ac46805461b014 100644
--- a/sdk/lib/isolate/isolate.dart
+++ b/sdk/lib/isolate/isolate.dart
@@ -495,25 +495,40 @@ class Isolate {
* be the same object types as in the actual isolate, but they will
* always have the same [Object.toString] result.
*
- * This stream is based on [addErrorListener] and [removeErrorListener].
+ * The returned stream is done when the isolate terminates.
+ *
+ * If the isolate has already terminated, the stream will never emit
+ * any events, not even a done event.
+ * If the isolate terminates while nobody is listening, the returned
floitsch 2016/12/07 16:12:00 Doesn't this sentence imply the first one?
+ * stream will also not emit a done event.
+ *
+ * This stream is based on [addErrorListener], [removeErrorListener],
+ * [addOnExitListener] and [removeOnExitListener].
*/
Stream get errors {
StreamController controller;
RawReceivePort port;
void handleError(message) {
- String errorDescription = message[0];
- String stackDescription = message[1];
- var error = new RemoteError(errorDescription, stackDescription);
- controller.addError(error, error.stackTrace);
+ if (message != null) {
+ String errorDescription = message[0];
+ String stackDescription = message[1];
+ var error = new RemoteError(errorDescription, stackDescription);
+ controller.addError(error, error.stackTrace);
+ } else {
+ port.close();
+ controller.close();
+ }
}
controller = new StreamController.broadcast(
sync: true,
onListen: () {
port = new RawReceivePort(handleError);
+ this.addOnExitListener(port.sendPort);
this.addErrorListener(port.sendPort);
},
onCancel: () {
this.removeErrorListener(port.sendPort);
+ this.removeOnExitListener(port.sendPort);
port.close();
port = null;
});
« no previous file with comments | « no previous file | tests/isolate/isolate_errors_test.dart » ('j') | tests/isolate/isolate_errors_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698