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

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

Issue 1074223002: Update Isolate API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix typo Created 5 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/isolate_patch.dart ('k') | tests/isolate/kill2_test.dart » ('j') | 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 * 56 *
57 * An `Isolate` object cannot be sent over a `SendPort`, but the control port 57 * An `Isolate` object cannot be sent over a `SendPort`, but the control port
58 * and capabilities can be sent, and can be used to create a new functioning 58 * and capabilities can be sent, and can be used to create a new functioning
59 * `Isolate` object in the receiving port's isolate. 59 * `Isolate` object in the receiving port's isolate.
60 */ 60 */
61 class Isolate { 61 class Isolate {
62 /** Argument to `ping` and `kill`: Ask for immediate action. */ 62 /** Argument to `ping` and `kill`: Ask for immediate action. */
63 static const int IMMEDIATE = 0; 63 static const int IMMEDIATE = 0;
64 /** Argument to `ping` and `kill`: Ask for action before the next event. */ 64 /** Argument to `ping` and `kill`: Ask for action before the next event. */
65 static const int BEFORE_NEXT_EVENT = 1; 65 static const int BEFORE_NEXT_EVENT = 1;
66 /** Argument to `ping` and `kill`: Ask for action after normal events. */
67 static const int AS_EVENT = 2;
68 66
69 /** 67 /**
70 * Control port used to send control messages to the isolate. 68 * Control port used to send control messages to the isolate.
71 * 69 *
72 * This class provides helper functions that sends control messages 70 * This class provides helper functions that sends control messages
73 * to the control port. 71 * to the control port.
74 * 72 *
75 * The control port identifies the isolate. 73 * The control port identifies the isolate.
76 */ 74 */
77 final SendPort controlPort; 75 final SendPort controlPort;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 * 250 *
253 * When all active pause requests have been cancelled, the isolate 251 * When all active pause requests have been cancelled, the isolate
254 * will continue handling normal messages. 252 * will continue handling normal messages.
255 * 253 *
256 * The capability must be one returned by a call to [pause] on this 254 * The capability must be one returned by a call to [pause] on this
257 * isolate, otherwise the resume call does nothing. 255 * isolate, otherwise the resume call does nothing.
258 */ 256 */
259 external void resume(Capability resumeCapability); 257 external void resume(Capability resumeCapability);
260 258
261 /** 259 /**
262 * Asks the isolate to send a message on [responsePort] when it terminates. 260 * Asks the isolate to send [response] on [responsePort] when it terminates.
263 * 261 *
264 * WARNING: This method is experimental and not handled on every platform yet. 262 * WARNING: This method is experimental and not handled on every platform yet.
265 * 263 *
266 * The isolate will send a `null` message on [responsePort] as the last 264 * The isolate will send a `response` message on `responsePort` as the last
267 * thing before it terminates. It will run no further code after the message 265 * thing before it terminates. It will run no further code after the message
268 * has been sent. 266 * has been sent.
269 * 267 *
268 * Adding the same port more than once will only cause it to receive one
269 * message, using the last response value that was added.
270 *
270 * If the isolate is already dead, no message will be sent. 271 * If the isolate is already dead, no message will be sent.
272 * If `response` cannot be sent to the isolate, then the request is ignored.
273 * It is recommended to only use simple values that can be sent to all
274 * isolates, like `null`, booleans, numbers or strings.
271 */ 275 */
272 /* TODO(lrn): Can we do better? Can the system recognize this message and 276 /* TODO(lrn): Can we do better? Can the system recognize this message and
273 * send a reply if the receiving isolate is dead? 277 * send a reply if the receiving isolate is dead?
274 */ 278 */
275 external void addOnExitListener(SendPort responsePort); 279 external void addOnExitListener(SendPort responsePort, {Object response});
276 280
277 /** 281 /**
278 * Stop listening on exit messages from the isolate. 282 * Stop listening on exit messages from the isolate.
279 * 283 *
280 * WARNING: This method is experimental and not handled on every platform yet. 284 * WARNING: This method is experimental and not handled on every platform yet.
281 * 285 *
282 * If a call has previously been made to [addOnExitListener] with the same 286 * If a call has previously been made to [addOnExitListener] with the same
283 * send-port, this will unregister the port, and it will no longer receive 287 * send-port, this will unregister the port, and it will no longer receive
284 * a message when the isolate terminates. 288 * a message when the isolate terminates.
285 * A response may still be sent until this operation is fully processed by 289 * A response may still be sent until this operation is fully processed by
(...skipping 15 matching lines...) Expand all
301 external void setErrorsFatal(bool errorsAreFatal); 305 external void setErrorsFatal(bool errorsAreFatal);
302 306
303 /** 307 /**
304 * Requests the isolate to shut down. 308 * Requests the isolate to shut down.
305 * 309 *
306 * WARNING: This method is experimental and not handled on every platform yet. 310 * WARNING: This method is experimental and not handled on every platform yet.
307 * 311 *
308 * The isolate is requested to terminate itself. 312 * The isolate is requested to terminate itself.
309 * The [priority] argument specifies when this must happen. 313 * The [priority] argument specifies when this must happen.
310 * 314 *
311 * The [priority] must be one of [IMMEDIATE], [BEFORE_NEXT_EVENT] or 315 * The [priority] must be one of [IMMEDIATE] or [BEFORE_NEXT_EVENT].
312 * [AS_EVENT].
313 * The shutdown is performed at different times depending on the priority: 316 * The shutdown is performed at different times depending on the priority:
314 * 317 *
315 * * `IMMEDIATE`: The the isolate shuts down as soon as possible. 318 * * `IMMEDIATE`: The the isolate shuts down as soon as possible.
316 * Control messages are handled in order, so all previously sent control 319 * Control messages are handled in order, so all previously sent control
317 * events from this isolate will all have been processed. 320 * events from this isolate will all have been processed.
318 * The shutdown should happen no later than if sent with 321 * The shutdown should happen no later than if sent with
319 * `BEFORE_NEXT_EVENT`. 322 * `BEFORE_NEXT_EVENT`.
320 * It may happen earlier if the system has a way to shut down cleanly 323 * It may happen earlier if the system has a way to shut down cleanly
321 * at an earlier time, even during the execution of another event. 324 * at an earlier time, even during the execution of another event.
322 * * `BEFORE_NEXT_EVENT`: The shutdown is scheduled for the next time 325 * * `BEFORE_NEXT_EVENT`: The shutdown is scheduled for the next time
323 * control returns to the event loop of the receiving isolate, 326 * control returns to the event loop of the receiving isolate,
324 * after the current event, and any already scheduled control events, 327 * after the current event, and any already scheduled control events,
325 * are completed. 328 * are completed.
326 * * `AS_EVENT`: The shutdown does not happen until all prevously sent
327 * non-control messages from the current isolate to the receiving isolate
328 * have been processed.
329 * The kill operation effectively puts the shutdown into the normal event
330 * queue after previously sent messages, and it is affected by any control
331 * messages that affect normal events, including `pause`.
332 * This can be used to wait for a another event to be processed.
333 */ 329 */
334 external void kill([int priority = BEFORE_NEXT_EVENT]); 330 external void kill({int priority: BEFORE_NEXT_EVENT});
335 331
336 /** 332 /**
337 * Request that the isolate send a response on the [responsePort]. 333 * Request that the isolate send [response] on the [responsePort].
338 * 334 *
339 * WARNING: This method is experimental and not handled on every platform yet. 335 * WARNING: This method is experimental and not handled on every platform yet.
340 * 336 *
341 * If the isolate is alive, it will eventually send a `null` response on 337 * If the isolate is alive, it will eventually send `response`
342 * the response port. 338 * (defaulting to `null`) on the response port.
343 * 339 *
344 * The [pingType] must be one of [IMMEDIATE], [BEFORE_NEXT_EVENT] or 340 * The [priority] must be one of [IMMEDIATE] or [BEFORE_NEXT_EVENT].
345 * [AS_EVENT].
346 * The response is sent at different times depending on the ping type: 341 * The response is sent at different times depending on the ping type:
347 * 342 *
348 * * `IMMEDIATE`: The the isolate responds as soon as it receives the 343 * * `IMMEDIATE`: The the isolate responds as soon as it receives the
349 * control message. This is after any previous control message 344 * control message. This is after any previous control message
350 * from the same isolate has been received. 345 * from the same isolate has been received, but may be during
346 * execution of another event.
351 * * `BEFORE_NEXT_EVENT`: The response is scheduled for the next time 347 * * `BEFORE_NEXT_EVENT`: The response is scheduled for the next time
352 * control returns to the event loop of the receiving isolate, 348 * control returns to the event loop of the receiving isolate,
353 * after the current event, and any already scheduled control events, 349 * after the current event, and any already scheduled control events,
354 * are completed. 350 * are completed.
355 * * `AS_EVENT`: The response is not sent until all prevously sent 351 *
356 * non-control messages from the current isolate to the receiving isolate 352 * If `response` cannot be sent to the isolate, then the request is ignored.
357 * have been processed. 353 * It is recommended to only use simple values that can be sent to all
358 * The ping effectively puts the response into the normal event queue 354 * isolates, like `null`, booleans, numbers or strings.
359 * after previously sent messages, and it is affected by any control
360 * messages that affect normal events, including `pause`.
361 * This can be used to wait for a another event to be processed.
362 */ 355 */
363 external void ping(SendPort responsePort, [int pingType = IMMEDIATE]); 356 external void ping(SendPort responsePort, {Object response,
357 int priority: IMMEDIATE});
364 358
365 /** 359 /**
366 * Requests that uncaught errors of the isolate are sent back to [port]. 360 * Requests that uncaught errors of the isolate are sent back to [port].
367 * 361 *
368 * WARNING: This method is experimental and not handled on every platform yet. 362 * WARNING: This method is experimental and not handled on every platform yet.
369 * 363 *
370 * The errors are sent back as two elements lists. 364 * The errors are sent back as two elements lists.
371 * The first element is a `String` representation of the error, usually 365 * The first element is a `String` representation of the error, usually
372 * created by calling `toString` on the error. 366 * created by calling `toString` on the error.
373 * The second element is a `String` representation of an accompanying 367 * The second element is a `String` representation of an accompanying
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 : _description = description, 603 : _description = description,
610 stackTrace = new _RemoteStackTrace(stackDescription); 604 stackTrace = new _RemoteStackTrace(stackDescription);
611 String toString() => _description; 605 String toString() => _description;
612 } 606 }
613 607
614 class _RemoteStackTrace implements StackTrace { 608 class _RemoteStackTrace implements StackTrace {
615 String _trace; 609 String _trace;
616 _RemoteStackTrace(this._trace); 610 _RemoteStackTrace(this._trace);
617 String toString() => _trace; 611 String toString() => _trace;
618 } 612 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/isolate_patch.dart ('k') | tests/isolate/kill2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698