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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Concurrent programming using _isolates_: 6 * Concurrent programming using _isolates_:
7 * independent workers that are similar to threads 7 * independent workers that are similar to threads
8 * but don't share memory, 8 * but don't share memory,
9 * communicating only via messages. 9 * communicating only via messages.
10 * 10 *
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 488
489 /** 489 /**
490 * Returns a broadcast stream of uncaught errors from the isolate. 490 * Returns a broadcast stream of uncaught errors from the isolate.
491 * 491 *
492 * Each error is provided as an error event on the stream. 492 * Each error is provided as an error event on the stream.
493 * 493 *
494 * The actual error object and stackTraces will not necessarily 494 * The actual error object and stackTraces will not necessarily
495 * be the same object types as in the actual isolate, but they will 495 * be the same object types as in the actual isolate, but they will
496 * always have the same [Object.toString] result. 496 * always have the same [Object.toString] result.
497 * 497 *
498 * This stream is based on [addErrorListener] and [removeErrorListener]. 498 * The returned stream is done when the isolate terminates.
499 *
500 * If the isolate has already terminated, the stream will never emit
501 * any events, not even a done event.
502 * 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?
503 * stream will also not emit a done event.
504 *
505 * This stream is based on [addErrorListener], [removeErrorListener],
506 * [addOnExitListener] and [removeOnExitListener].
499 */ 507 */
500 Stream get errors { 508 Stream get errors {
501 StreamController controller; 509 StreamController controller;
502 RawReceivePort port; 510 RawReceivePort port;
503 void handleError(message) { 511 void handleError(message) {
504 String errorDescription = message[0]; 512 if (message != null) {
505 String stackDescription = message[1]; 513 String errorDescription = message[0];
506 var error = new RemoteError(errorDescription, stackDescription); 514 String stackDescription = message[1];
507 controller.addError(error, error.stackTrace); 515 var error = new RemoteError(errorDescription, stackDescription);
516 controller.addError(error, error.stackTrace);
517 } else {
518 port.close();
519 controller.close();
520 }
508 } 521 }
509 controller = new StreamController.broadcast( 522 controller = new StreamController.broadcast(
510 sync: true, 523 sync: true,
511 onListen: () { 524 onListen: () {
512 port = new RawReceivePort(handleError); 525 port = new RawReceivePort(handleError);
526 this.addOnExitListener(port.sendPort);
513 this.addErrorListener(port.sendPort); 527 this.addErrorListener(port.sendPort);
514 }, 528 },
515 onCancel: () { 529 onCancel: () {
516 this.removeErrorListener(port.sendPort); 530 this.removeErrorListener(port.sendPort);
531 this.removeOnExitListener(port.sendPort);
517 port.close(); 532 port.close();
518 port = null; 533 port = null;
519 }); 534 });
520 return controller.stream; 535 return controller.stream;
521 } 536 }
522 } 537 }
523 538
524 /** 539 /**
525 * Sends messages to its [ReceivePort]s. 540 * Sends messages to its [ReceivePort]s.
526 * 541 *
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 * as the original error, but has no other features of the original error. 685 * as the original error, but has no other features of the original error.
671 */ 686 */
672 class RemoteError implements Error { 687 class RemoteError implements Error {
673 final String _description; 688 final String _description;
674 final StackTrace stackTrace; 689 final StackTrace stackTrace;
675 RemoteError(String description, String stackDescription) 690 RemoteError(String description, String stackDescription)
676 : _description = description, 691 : _description = description,
677 stackTrace = new StackTrace.fromString(stackDescription); 692 stackTrace = new StackTrace.fromString(stackDescription);
678 String toString() => _description; 693 String toString() => _description;
679 } 694 }
OLDNEW
« 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