Chromium Code Reviews| Index: sdk/lib/isolate/isolate.dart |
| diff --git a/sdk/lib/isolate/isolate.dart b/sdk/lib/isolate/isolate.dart |
| index 3ae06e9b7c75ec0b9a055d4cfbe23f785ba2d996..13e0d8877c618294ea0e5e8150ba794436fe1da3 100644 |
| --- a/sdk/lib/isolate/isolate.dart |
| +++ b/sdk/lib/isolate/isolate.dart |
| @@ -29,12 +29,12 @@ 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; |
| + /** Argument to `ping` and `kill`: Ask for immediate action. */ |
| + static const int OUT_OF_BAND = 0; |
|
Anders Johnsen
2014/03/19 13:15:34
IMMEDIATE?
People should not need to know about O
Søren Gjesse
2014/03/20 08:08:33
Agree with Anders. ASAP is also an option, but tha
Lasse Reichstein Nielsen
2014/03/20 13:12:33
I tried ASAP, and it didn't really work.
IMMEDIAT
|
| + /** Argument to `ping` and `kill`: Ask for action before the next event. */ |
| + static const int BEFORE_NEXT_EVENT = 1; |
|
Anders Johnsen
2014/03/19 13:15:34
Not sure if I have another name for this one.
Søren Gjesse
2014/03/20 08:08:33
HEAD_OF_QUEUE?
Lasse Reichstein Nielsen
2014/03/20 13:12:33
I prefer to talk about "events" rather than "queue
|
| + /** Argument to `ping` and `kill`: Ask for action after normal events. */ |
| + static const int AS_EVENT = 2; |
|
Anders Johnsen
2014/03/19 13:15:34
END_OF_QUEUE?
Søren Gjesse
2014/03/20 08:08:33
Using HEAD_OF_QUEUE / END_OF_QUEUE has some symmet
Anders Johnsen
2014/03/20 08:48:01
+1
Lasse Reichstein Nielsen
2014/03/20 13:12:33
HEAD_OF_QUEUE sounds like it is in the queue, whic
|
| /** |
| * Control port used to send control messages to the isolate. |
| @@ -115,7 +115,6 @@ class Isolate { |
| external static Future<Isolate> spawnUri( |
| Uri uri, List<String> args, var message, { bool paused: false }); |
| - |
| /** |
| * Requests the isolate to pause. |
| * |
| @@ -232,6 +231,41 @@ class Isolate { |
| } |
| /** |
| + * Requests the isolate to shut down. |
| + * |
| + * WARNING: This method is experimental and not handled on every platform yet. |
| + * |
| + * The isolate is requested to terminate itself. |
| + * The [priority] argument specifies when this must happen. |
| + * |
| + * The [priority] must be one of [OUT_OF_BAND], [BEFORE_NEXT_EVENT] or |
| + * [AS_EVENT]. |
| + * The shutdown is performed at different times depending on the priority: |
| + * |
| + * * `OUT_OF_BAND`: The the isolate shuts down as soon as possible. |
| + * Control messages are handled in order, so all previously sent control |
| + * events from this isolate will all have been processed. |
| + * The shutdown should happen no later than if sent with |
| + * `BEFORE_NEXT_EVENT`. |
| + * It may happen earlier if the system has a way to shut down cleanly |
| + * at an earlier time, even during the execution of another event. |
| + * * `BEFORE_NEXT_EVENT`: The shutdown is scheduled for the next time |
| + * control returns to the event loop of the receiving isolate. |
| + * If more than one such event are scheduled, they are executed in |
| + * the order their control messages were received. |
| + * * `AS_EVENT`: The shutdown dows not happen until all prevously sent |
| + * non-control messages from the current isolate to the receiving isolate |
| + * have been processed. |
| + * The kill operation effectively puts the shutdown into the normal event |
| + * queue after previously sent messages, and it is affected by any control |
| + * messages that affect normal events, including `pause`. |
| + * This can be used to wait for a another event to be processed. |
| + */ |
| + void kill([int priority = BEFORE_NEXT_EVENT]) { |
| + controlPort.send(["kill", terminateCapability, priority]); |
| + } |
| + |
| + /** |
| * Request that the isolate send a response on the [responsePort]. |
| * |
| * WARNING: This method is experimental and not handled on every platform yet. |
| @@ -239,24 +273,25 @@ class Isolate { |
| * 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 [pingType] must be one of [OUT_OF_BAND], [BEFORE_NEXT_EVENT] or |
| + * [AS_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 |
| + * * `OUT_OF_BAND`: The the isolate responds as soon as it receives the |
| + * control message. |
| + * * `BEFORE_NEXT_EVENT`: The response is scheduled for the next time |
| + * control returns to the event loop of the receiving isolate. |
| + * If more than one such event are scheduled, they are executed in |
| + * the order their control messages were received. |
| + * * `AS_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. |
| + * The ping effectively puts the response into the normal event queue |
| + * after previously sent messages, and it is affected by any control |
| + * messages that affect normal events, including `pause`. |
| * This can be used to wait for a another event to be processed. |
| */ |
| - void ping(SendPort responsePort, [int pingType = PING_ALIVE]) { |
| + void ping(SendPort responsePort, [int pingType = OUT_OF_BAND]) { |
| var message = new List(3) |
| ..[0] = "ping" |
| ..[1] = responsePort |