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