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

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

Issue 142703010: Add pause methods to Isolate. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/isolate/isolate.status » ('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 7cf0b3613cf50b43ab98445c4e3ef7eb32631d27..4a5b50a62af7971c82718cc7120e2f0f5e077169 100644
--- a/sdk/lib/isolate/isolate.dart
+++ b/sdk/lib/isolate/isolate.dart
@@ -29,11 +29,16 @@ class IsolateSpawnException implements Exception {
}
class Isolate {
+ /**
+ * Control port used to send control messages to the isolate.
+ *
+ * This class provides helper functions that sends control messages
+ * to the control port.
+ */
+ final SendPort controlPort;
+ final Capability pauseCapability;
- final SendPort _controlPort;
-
- Isolate._fromControlPort(SendPort controlPort)
- : this._controlPort = controlPort;
+ Isolate._fromControlPort(this.controlPort, [this.pauseCapability]);
/**
* Creates and spawns an isolate that shares the same code as the current
@@ -76,6 +81,57 @@ class Isolate {
*/
external static Future<Isolate> spawnUri(
Uri uri, List<String> args, var message);
+
+
+ /**
+ * Requests the isolate to pause.
+ *
+ * The isolate should stop handling events by pausing its event queue.
+ * The request will eventually make the isolate stop doing anything.
+ * It will be handled before any other messages sent to the isolate from
+ * the current isolate, but no other guarantees are provided.
+ *
+ * If [resumeCapability] is provided, it is used to identity the pause,
+ * and must be used again to end the pause using [resume].
+ * Otherwise a new capability is created and returned.
+ *
+ * If an isolate is paused more than once using the same capabilty,
+ * only one resume with that capability is needed to end the pause.
+ *
+ * If an isolate is paused using more than one capability,
+ * they must all be individully ended before the isolate resumes.
+ *
+ * Returns the capability that must be used to resume end the pause.
+ *
+ * WARNING: This method is not handled on any platform yet.
+ */
+ Capability pause([Capability resumeCapability]) {
+ if (resumeCapability == null) resumeCapability = new Capability();
+ var message = new List(3)
+ ..[0] = "pause"
+ ..[1] = pauseCapability
+ ..[2] = resumeCapability;
+ controlPort.send(message);
+ return resumeCapability;
+ }
+
+ /**
+ * Resumes a paused isolate.
+ *
+ * Sends a message to an isolate requesting that it ends a pause
+ * that was requested using the [resumeCapability].
+ *
+ * The capability must be one returned by a call to [pause] on this
+ * isolate, otherwise the resume call does nothing.
+ *
+ * WARNING: This method is not handled on any platform yet.
+ */
+ void resume(Capability resumeCapability) {
+ var message = new List(2)
+ ..[0] = "resume"
+ ..[1] = resumeCapability;
+ controlPort.send(message);
+ }
}
/**
« no previous file with comments | « no previous file | tests/isolate/isolate.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698