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

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

Issue 1240743003: Add errorsAreFatal, onExit and onError parameters to the spawn functions. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix typo Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/js_runtime/lib/isolate_patch.dart ('k') | no next file » | no next file with comments »
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 9b488c21bb243150f8e52c68dd02c3034e105f67..9a8b313f51537d937a0a7cd04daf8a973d73043b 100644
--- a/sdk/lib/isolate/isolate.dart
+++ b/sdk/lib/isolate/isolate.dart
@@ -144,15 +144,30 @@ class Isolate {
* If the [paused] parameter is set to `true`,
* the isolate will start up in a paused state,
* as if by an initial call of `isolate.pause(isolate.pauseCapability)`.
- * This allows setting up error or exit listeners on the isolate
- * before it starts running.
* To resume the isolate, call `isolate.resume(isolate.pauseCapability)`.
*
+ * If the [errorAreFatal], [onExit] and/or [onError] parameters are provided,
+ * the isolate will act as if, respectively, [setErrorsFatal],
+ * [addOnExitListener] and [addErrorListener] were called with the
+ * corresponding parameter and was processed before the isolate starts
+ * running.
+ *
+ * You can also call the [setErrorsFatal], [addOnExitListener] and
+ * [addErrorListener] methods on the returned isolate, but unless the
+ * isolate was started as [paused], it may already have terminated
+ * before those methods can complete.
+ *
+ * WARNING: The [errorsAreFatal], [onExit] and [onError] parameters are not
+ * implemented yet.
+ *
* Returns a future that will complete with an [Isolate] instance if the
* spawning succeeded. It will complete with an error otherwise.
*/
external static Future<Isolate> spawn(void entryPoint(message), var message,
- { bool paused: false });
+ { bool paused: false,
+ bool errorsAreFatal,
+ SendPort onExit,
+ SendPort onError });
/**
* Creates and spawns an isolate that runs the code from the library with
@@ -161,7 +176,8 @@ class Isolate {
* The isolate starts executing the top-level `main` function of the library
* with the given URI.
*
- * The target `main` must be a subtype of one of these three signatures:
+ * The target `main` must be callable with zero, one or two arguments.
+ * Examples:
*
* * `main()`
* * `main(args)`
@@ -173,10 +189,22 @@ class Isolate {
* If the [paused] parameter is set to `true`,
* the isolate will start up in a paused state,
* as if by an initial call of `isolate.pause(isolate.pauseCapability)`.
- * This allows setting up error or exit listeners on the isolate
- * before it starts running.
* To resume the isolate, call `isolate.resume(isolate.pauseCapability)`.
*
+ * If the [errorAreFatal], [onExit] and/or [onError] parameters are provided,
+ * the isolate will act as if, respectively, [setErrorsFatal],
+ * [addOnExitListener] and [addErrorListener] were called with the
+ * corresponding parameter and was processed before the isolate starts
+ * running.
+ *
+ * You can also call the [setErrorsFatal], [addOnExitListener] and
+ * [addErrorListener] methods on the returned isolate, but unless the
+ * isolate was started as [paused], it may already have terminated
+ * before those methods can complete.
+ *
+ * WARNING: The [errorsAreFatal], [onExit] and [onError] parameters are not
+ * implemented yet.
+ *
* If the [checked] parameter is set to `true` or `false`,
* the new isolate will run code in checked mode,
* respectively in production mode, if possible.
@@ -214,7 +242,10 @@ class Isolate {
var message,
{bool paused: false,
bool checked,
- Uri packageRoot});
+ Uri packageRoot,
+ bool errorsAreFatal,
+ SendPort onExit,
+ SendPort onError});
/**
* Requests the isolate to pause.
@@ -276,10 +307,13 @@ class Isolate {
* If `response` cannot be sent to the isolate, then the request is ignored.
* It is recommended to only use simple values that can be sent to all
* isolates, like `null`, booleans, numbers or strings.
- *
+ *
* Since isolates run concurrently, it's possible for it to exit before the
- * exit listener is established. To avoid this, start the isolate paused,
- * add the listener, then resume it.
+ * exit listener is established, and in that case no response will be
+ * sent on [responsePort].
+ * To avoid this, either use the corresponding parameter to the spawn
+ * function, or start the isolate paused, add the listener and
+ * then resume the isolate.
*/
/* TODO(lrn): Can we do better? Can the system recognize this message and
* send a reply if the receiving isolate is dead?
@@ -305,6 +339,12 @@ class Isolate {
*
* This call requires the [terminateCapability] for the isolate.
* If the capability is not correct, no change is made.
+ *
+ * Since isolates run concurrently, it's possible for it to exit due to an
+ * error before errors are set non-fatal.
+ * To avoid this, either use the corresponding parameter to the spawn
+ * function, or start the isolate paused, set errors non-fatal and
+ * then resume the isolate.
*/
external void setErrorsFatal(bool errorsAreFatal);
@@ -368,10 +408,10 @@ class Isolate {
*
* Listening using the same port more than once does nothing. It will only
* get each error once.
- *
+ *
* Since isolates run concurrently, it's possible for it to exit before the
* error listener is established. To avoid this, start the isolate paused,
- * add the listener, then resume it.
+ * add the listener and then resume the isolate.
*/
external void addErrorListener(SendPort port);
« no previous file with comments | « sdk/lib/_internal/js_runtime/lib/isolate_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698