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

Side by Side Diff: sdk/lib/isolate/isolate.dart

Issue 2659873002: Update documentation on `Isolate.removeOnExitListener` and others. (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 * When all active pause requests have been cancelled, the isolate 372 * When all active pause requests have been cancelled, the isolate
373 * will continue processing events and handling normal messages. 373 * will continue processing events and handling normal messages.
374 * 374 *
375 * If the [resumeCapability] is not one that has previously been used 375 * If the [resumeCapability] is not one that has previously been used
376 * to pause the isolate, or it has already been used to resume from 376 * to pause the isolate, or it has already been used to resume from
377 * that pause, the resume call has no effect. 377 * that pause, the resume call has no effect.
378 */ 378 */
379 external void resume(Capability resumeCapability); 379 external void resume(Capability resumeCapability);
380 380
381 /** 381 /**
382 * Asks the isolate to send [response] on [responsePort] when it terminates. 382 * Requests an exist message on [responsePort] when the isolate terminates.
383 * 383 *
384 * The isolate will send a `response` message on `responsePort` as the last 384 * The isolate will send [response] as a message on [responsePort] as the last
385 * thing before it terminates. It will run no further code after the message 385 * thing before it terminates. It will run no further code after the message
386 * has been sent. 386 * has been sent.
387 * 387 *
388 * Adding the same port more than once will only cause it to receive one 388 * Adding the same port more than once will only cause it to receive one exit
389 * message, using the last response value that was added. 389 * message, using the last response value that was added,
390 * and it only needs to be removed once using [removeOnExitListener].
390 * 391 *
391 * If the isolate is already dead, no message will be sent. 392 * If the isolate is already dead, no exit message will be sent.
floitsch 2017/01/30 11:12:14 is already dead when? When you add an exit listene
Lasse Reichstein Nielsen 2017/01/30 12:08:13 Reworded: If the isolate has terminated before it
392 * 393 *
393 * The [response] object must follow the same restrictions as enforced by 394 * The [response] object must follow the same restrictions as enforced by
394 * [SendPort.send]. 395 * [SendPort.send].
395 * It is recommended to only use simple values that can be sent to all 396 * It is recommended to only use simple values that can be sent to all
396 * isolates, like `null`, booleans, numbers or strings. 397 * isolates, like `null`, booleans, numbers or strings.
397 * 398 *
398 * Since isolates run concurrently, it's possible for it to exit before the 399 * Since isolates run concurrently, it's possible for it to exit before the
399 * exit listener is established, and in that case no response will be 400 * exit listener is established, and in that case no response will be
400 * sent on [responsePort]. 401 * sent on [responsePort].
401 * To avoid this, either use the corresponding parameter to the spawn 402 * To avoid this, either use the corresponding parameter to the spawn
402 * function, or start the isolate paused, add the listener and 403 * function, or start the isolate paused, add the listener and
403 * then resume the isolate. 404 * then resume the isolate.
404 */ 405 */
405 /* TODO(lrn): Can we do better? Can the system recognize this message and 406 /* TODO(lrn): Can we do better? Can the system recognize this message and
406 * send a reply if the receiving isolate is dead? 407 * send a reply if the receiving isolate is dead?
407 */ 408 */
408 external void addOnExitListener(SendPort responsePort, {Object response}); 409 external void addOnExitListener(SendPort responsePort, {Object response});
409 410
410 /** 411 /**
411 * Stop listening on exit messages from the isolate. 412 * Stop listening for exit messages from the isolate.
412 * 413 *
413 * If a call has previously been made to [addOnExitListener] with the same 414 * Requests for the isolate to not send exit messages on [responsePort].
414 * send-port, this will unregister the port, and it will no longer receive 415 * If the isolate isn't expecting to send exit messages on [responsePort],
415 * a message when the isolate terminates. 416 * because the port hasn't been added using [addOnExitListener],
416 * A response may still be sent until this operation is fully processed by 417 * or because it has already been removed, the request is ignored.
417 * the isolate. 418 *
419 * If the same port has been passed via [addOnExitListener] more than once,
420 * only one call to `removeOnExitListener` is needed to stop it from receiving
421 * exit messagees.
422 *
423 * Closing the receive port at the end of the send port will not stop the
424 * isolate from sending exit messages, they are just going to be lost.
425 *
426 * An exit message may still be sent if the isolate terminates
427 * before this request is received and processed.
418 */ 428 */
419 external void removeOnExitListener(SendPort responsePort); 429 external void removeOnExitListener(SendPort responsePort);
420 430
421 /** 431 /**
422 * Set whether uncaught errors will terminate the isolate. 432 * Set whether uncaught errors will terminate the isolate.
423 * 433 *
424 * If errors are fatal, any uncaught error will terminate the isolate 434 * If errors are fatal, any uncaught error will terminate the isolate
425 * event loop and shut down the isolate. 435 * event loop and shut down the isolate.
426 * 436 *
427 * This call requires the [terminateCapability] for the isolate. 437 * This call requires the [terminateCapability] for the isolate.
428 * If the capability absent or wrong, no change is made. 438 * If the capability is absent or incorrect, no change is made.
429 * 439 *
430 * Since isolates run concurrently, it's possible for it to exit due to an 440 * Since isolates run concurrently, it's possible for it to exit due to an
431 * error before errors are set non-fatal. 441 * error before errors are set non-fatal.
432 * To avoid this, either use the corresponding parameter to the spawn 442 * To avoid this, either use the corresponding parameter to the spawn
433 * function, or start the isolate paused, set errors non-fatal and 443 * function, or start the isolate paused, set errors non-fatal and
434 * then resume the isolate. 444 * then resume the isolate.
435 */ 445 */
436 external void setErrorsFatal(bool errorsAreFatal); 446 external void setErrorsFatal(bool errorsAreFatal);
437 447
438 /** 448 /**
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 * isolates, like `null`, booleans, numbers or strings. 482 * isolates, like `null`, booleans, numbers or strings.
473 * 483 *
474 * If the isolate is alive, it will eventually send `response` 484 * If the isolate is alive, it will eventually send `response`
475 * (defaulting to `null`) on the response port. 485 * (defaulting to `null`) on the response port.
476 * 486 *
477 * The [priority] must be one of [IMMEDIATE] or [BEFORE_NEXT_EVENT]. 487 * The [priority] must be one of [IMMEDIATE] or [BEFORE_NEXT_EVENT].
478 * The response is sent at different times depending on the ping type: 488 * The response is sent at different times depending on the ping type:
479 * 489 *
480 * * `IMMEDIATE`: The isolate responds as soon as it receives the 490 * * `IMMEDIATE`: The isolate responds as soon as it receives the
481 * control message. This is after any previous control message 491 * control message. This is after any previous control message
482 * from the same isolate has been received, but may be during 492 * from the same isolate has been received and processed,
483 * execution of another event. 493 * but may be during execution of another event.
484 * * `BEFORE_NEXT_EVENT`: The response is scheduled for the next time 494 * * `BEFORE_NEXT_EVENT`: The response is scheduled for the next time
485 * control returns to the event loop of the receiving isolate, 495 * control returns to the event loop of the receiving isolate,
486 * after the current event, and any already scheduled control events, 496 * after the current event, and any already scheduled control events,
487 * are completed. 497 * are completed.
488 */ 498 */
489 external void ping(SendPort responsePort, {Object response, 499 external void ping(SendPort responsePort, {Object response,
490 int priority: IMMEDIATE}); 500 int priority: IMMEDIATE});
491 501
492 /** 502 /**
493 * Requests that uncaught errors of the isolate are sent back to [port]. 503 * Requests that uncaught errors of the isolate are sent back to [port].
494 * 504 *
495 * The errors are sent back as two elements lists. 505 * The errors are sent back as two elements lists.
496 * The first element is a `String` representation of the error, usually 506 * The first element is a `String` representation of the error, usually
497 * created by calling `toString` on the error. 507 * created by calling `toString` on the error.
498 * The second element is a `String` representation of an accompanying 508 * The second element is a `String` representation of an accompanying
499 * stack trace, or `null` if no stack trace was provided. 509 * stack trace, or `null` if no stack trace was provided.
500 * To convert this back to a [StackTrace] object, use [StackTrace.fromString]. 510 * To convert this back to a [StackTrace] object, use [StackTrace.fromString].
501 * 511 *
502 * Listening using the same port more than once does nothing. It will only 512 * Listening using the same port more than once does nothing.
503 * get each error once. 513 * A port will only receive each error once,
514 * and will only need to be removed once using [removeErrorListener].
504 * 515 *
505 * Since isolates run concurrently, it's possible for it to exit before the 516 * Since isolates run concurrently, it's possible for it to exit before the
506 * error listener is established. To avoid this, start the isolate paused, 517 * error listener is established. To avoid this, start the isolate paused,
507 * add the listener and then resume the isolate. 518 * add the listener and then resume the isolate.
508 */ 519 */
509 external void addErrorListener(SendPort port); 520 external void addErrorListener(SendPort port);
510 521
511 /** 522 /**
512 * Stop listening for uncaught errors through [port]. 523 * Stop listening for uncaught errors from the isolate.
513 * 524 *
514 * The `port` should be a port that is listening for errors through 525 * Requests for the isolate to not send uncaught errors on [responsePort].
515 * [addErrorListener]. This call requests that the isolate stops sending 526 * If the isolate isn't expecting to send uncaught errors on [responsePort],
516 * errors on the port. 527 * because the port hasn't been added using [addErrorListener],
528 * or because it has already been removed, the request is ignored.
517 * 529 *
518 * If the same port has been passed via `addErrorListener` more than once, 530 * If the same port has been passed via [addErrorListener] more than once,
519 * only one call to `removeErrorListener` is needed to stop it from receiving 531 * only one call to `removeErrorListener` is needed to stop it from receiving
520 * errors. 532 * unaught errors.
521 * 533 *
522 * Closing the receive port at the end of the send port will not stop the 534 * Closing the receive port at the end of the send port will not stop the
523 * isolate from sending errors, they are just going to be lost. 535 * isolate from sending uncaught errors, they are just going to be lost.
536 *
537 * Uncaught errors message may still be sent by the isolate
538 * until this request is received and processed.
524 */ 539 */
525 external void removeErrorListener(SendPort port); 540 external void removeErrorListener(SendPort port);
526 541
527 /** 542 /**
528 * Returns a broadcast stream of uncaught errors from the isolate. 543 * Returns a broadcast stream of uncaught errors from the isolate.
529 * 544 *
530 * Each error is provided as an error event on the stream. 545 * Each error is provided as an error event on the stream.
531 * 546 *
532 * The actual error object and stackTraces will not necessarily 547 * The actual error object and stackTraces will not necessarily
533 * be the same object types as in the actual isolate, but they will 548 * be the same object types as in the actual isolate, but they will
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 * as the original error, but has no other features of the original error. 723 * as the original error, but has no other features of the original error.
709 */ 724 */
710 class RemoteError implements Error { 725 class RemoteError implements Error {
711 final String _description; 726 final String _description;
712 final StackTrace stackTrace; 727 final StackTrace stackTrace;
713 RemoteError(String description, String stackDescription) 728 RemoteError(String description, String stackDescription)
714 : _description = description, 729 : _description = description,
715 stackTrace = new StackTrace.fromString(stackDescription); 730 stackTrace = new StackTrace.fromString(stackDescription);
716 String toString() => _description; 731 String toString() => _description;
717 } 732 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698