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

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

Issue 186403003: Add Isolate ping functionality. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 9 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/lib/isolate_helper.dart ('k') | tests/isolate/ping_pause_test.dart » ('j') | 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 47b57f969acb7189ffff618a5cccbb5d27b9db0e..3ae06e9b7c75ec0b9a055d4cfbe23f785ba2d996 100644
--- a/sdk/lib/isolate/isolate.dart
+++ b/sdk/lib/isolate/isolate.dart
@@ -29,6 +29,13 @@ class IsolateSpawnException implements Exception {
}
class Isolate {
+ /** Argument to `ping`: Ask for immediate response. */
+ static const int PING_ALIVE = 0;
+ /** Argument to `ping`: Ask for response after control events. */
+ static const int PING_CONTROL = 1;
+ /** Argument to `ping`: Ask for response after normal events. */
+ static const int PING_EVENT = 2;
+
/**
* Control port used to send control messages to the isolate.
*
@@ -223,6 +230,39 @@ class Isolate {
..[2] = errorsAreFatal;
controlPort.send(message);
}
+
+ /**
+ * Request that the isolate send a response on the [responsePort].
+ *
+ * WARNING: This method is experimental and not handled on every platform yet.
+ *
+ * If the isolate is alive, it will eventually send a `null` response on
+ * the response port.
+ *
+ * The [pingType] must be one of [PING_ALIVE], [PING_CONTROL] or [PING_EVENT].
+ * The response is sent at different times depending on the ping type:
+ *
+ * * `PING_ALIVE`: The the isolate responds as soon as possible.
+ * The response should happen no later than if sent with `PING_CONTROL`.
+ * It may be sent earlier if the system has a way to do so.
+ * * `PING_CONTROL`: The response it not sent until all previously sent
+ * control messages from the current isolate to the receiving isolate
+ * have been processed. This can be used to wait for
+ * previously sent control messages.
+ * * `PING_EVENT`: The response is not sent until all prevously sent
+ * non-control messages from the current isolate to the receiving isolate
+ * have been processed.
+ * The ping effectively puts the resonse into the normal event queue after
+ * previously sent messages.
+ * This can be used to wait for a another event to be processed.
+ */
+ void ping(SendPort responsePort, [int pingType = PING_ALIVE]) {
+ var message = new List(3)
+ ..[0] = "ping"
+ ..[1] = responsePort
+ ..[2] = pingType;
+ controlPort.send(message);
+ }
}
/**
« no previous file with comments | « sdk/lib/_internal/lib/isolate_helper.dart ('k') | tests/isolate/ping_pause_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698