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

Side by Side 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: 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 unified diff | 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 »
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 * It is not allowed to pass the value of function expressions or an instance 137 * It is not allowed to pass the value of function expressions or an instance
138 * method extracted from an object. 138 * method extracted from an object.
139 * 139 *
140 * The entry-point function is invoked with the initial [message]. 140 * The entry-point function is invoked with the initial [message].
141 * Usually the initial [message] contains a [SendPort] so 141 * Usually the initial [message] contains a [SendPort] so
142 * that the spawner and spawnee can communicate with each other. 142 * that the spawner and spawnee can communicate with each other.
143 * 143 *
144 * If the [paused] parameter is set to `true`, 144 * If the [paused] parameter is set to `true`,
145 * the isolate will start up in a paused state, 145 * the isolate will start up in a paused state,
146 * as if by an initial call of `isolate.pause(isolate.pauseCapability)`. 146 * as if by an initial call of `isolate.pause(isolate.pauseCapability)`.
147 * This allows setting up error or exit listeners on the isolate
148 * before it starts running.
149 * To resume the isolate, call `isolate.resume(isolate.pauseCapability)`. 147 * To resume the isolate, call `isolate.resume(isolate.pauseCapability)`.
150 * 148 *
149 * If the [errorAreFatal], [onExit] and/or [onError] parameters are provided,
150 * the isolate will act as if, respectively, [setErrorsFatal],
151 * [addOnExitListener] and [addErrorListener] were called with the
152 * corresponding parameter and was processed before the isolate starts
153 * running.
154 * You can also call the [setErrorsFatal], [addOnExitListener] and
floitsch 2015/07/15 13:55:09 I would add a new line before.
Lasse Reichstein Nielsen 2015/07/16 14:44:50 Done.
155 * [addErrorListener] methods on the returned isolate, but unless the
156 * isolate was started as [paused], it may already have terminated
157 * before those methods can complete.
158 *
159 * WARNING: The [errorsAreFatal], [onExit] and [onError] parameters are not
160 * implemented yet.
161 *
151 * Returns a future that will complete with an [Isolate] instance if the 162 * Returns a future that will complete with an [Isolate] instance if the
152 * spawning succeeded. It will complete with an error otherwise. 163 * spawning succeeded. It will complete with an error otherwise.
153 */ 164 */
154 external static Future<Isolate> spawn(void entryPoint(message), var message, 165 external static Future<Isolate> spawn(void entryPoint(message), var message,
155 { bool paused: false }); 166 { bool paused: false,
167 bool errorsAreFatal,
Ivan Posva 2015/07/16 11:37:52 What is the default value for errorsAreFatal? I th
Lasse Reichstein Nielsen 2015/07/16 14:44:50 I'm not sure there is one - browser isolates don't
168 SendPort onExit,
169 SendPort onError });
156 170
157 /** 171 /**
158 * Creates and spawns an isolate that runs the code from the library with 172 * Creates and spawns an isolate that runs the code from the library with
159 * the specified URI. 173 * the specified URI.
160 * 174 *
161 * The isolate starts executing the top-level `main` function of the library 175 * The isolate starts executing the top-level `main` function of the library
162 * with the given URI. 176 * with the given URI.
163 * 177 *
164 * The target `main` must be a subtype of one of these three signatures: 178 * The target `main` must be callable with zero, one or two arguments.
179 * Examples:
165 * 180 *
166 * * `main()` 181 * * `main()`
167 * * `main(args)` 182 * * `main(args)`
168 * * `main(args, message)` 183 * * `main(args, message)`
169 * 184 *
170 * When present, the parameter `args` is set to the provided [args] list. 185 * When present, the parameter `args` is set to the provided [args] list.
171 * When present, the parameter `message` is set to the initial [message]. 186 * When present, the parameter `message` is set to the initial [message].
172 * 187 *
173 * If the [paused] parameter is set to `true`, 188 * If the [paused] parameter is set to `true`,
174 * the isolate will start up in a paused state, 189 * the isolate will start up in a paused state,
175 * as if by an initial call of `isolate.pause(isolate.pauseCapability)`. 190 * as if by an initial call of `isolate.pause(isolate.pauseCapability)`.
176 * This allows setting up error or exit listeners on the isolate
177 * before it starts running.
178 * To resume the isolate, call `isolate.resume(isolate.pauseCapability)`. 191 * To resume the isolate, call `isolate.resume(isolate.pauseCapability)`.
179 * 192 *
193 * If the [errorAreFatal], [onExit] and/or [onError] parameters are provided,
194 * the isolate will act as if, respectively, [setErrorsFatal],
195 * [addOnExitListener] and [addErrorListener] were called with the
196 * corresponding parameter and was processed before the isolate starts
197 * running.
198 * You can call the [setErrorsFatal], [addOnExitListener] and
floitsch 2015/07/15 13:55:10 ditto.
Lasse Reichstein Nielsen 2015/07/16 14:44:50 Done.
199 * [addErrorListener] methods on the returned isolate, but unless the
200 * isolate was started as [paused], it may already have terminated
201 * before those methods can complete.
202 *
203 * WARNING: The [errorsAreFatal], [onExit] and [onError] parameters are not
204 * implemented yet.
205 *
180 * If the [checked] parameter is set to `true` or `false`, 206 * If the [checked] parameter is set to `true` or `false`,
181 * the new isolate will run code in checked mode, 207 * the new isolate will run code in checked mode,
182 * respectively in production mode, if possible. 208 * respectively in production mode, if possible.
183 * If the parameter is omitted, the new isolate will inherit the 209 * If the parameter is omitted, the new isolate will inherit the
184 * value from the current isolate. 210 * value from the current isolate.
185 * 211 *
186 * It may not always be possible to honor the `checked` parameter. 212 * It may not always be possible to honor the `checked` parameter.
187 * If the isolate code was pre-compiled, it may not be possible to change 213 * If the isolate code was pre-compiled, it may not be possible to change
188 * the checked mode setting dynamically. 214 * the checked mode setting dynamically.
189 * In that case, the `checked` parameter is ignored. 215 * In that case, the `checked` parameter is ignored.
(...skipping 17 matching lines...) Expand all
207 * 233 *
208 * Returns a future that will complete with an [Isolate] instance if the 234 * Returns a future that will complete with an [Isolate] instance if the
209 * spawning succeeded. It will complete with an error otherwise. 235 * spawning succeeded. It will complete with an error otherwise.
210 */ 236 */
211 external static Future<Isolate> spawnUri( 237 external static Future<Isolate> spawnUri(
212 Uri uri, 238 Uri uri,
213 List<String> args, 239 List<String> args,
214 var message, 240 var message,
215 {bool paused: false, 241 {bool paused: false,
216 bool checked, 242 bool checked,
217 Uri packageRoot}); 243 Uri packageRoot
244 bool errorsAreFatal,
245 SendPort onExit,
246 SendPort onError});
218 247
219 /** 248 /**
220 * Requests the isolate to pause. 249 * Requests the isolate to pause.
221 * 250 *
222 * The isolate should stop handling events by pausing its event queue. 251 * The isolate should stop handling events by pausing its event queue.
223 * The request will eventually make the isolate stop doing anything. 252 * The request will eventually make the isolate stop doing anything.
224 * It will be handled before any other messages that are later sent to the 253 * It will be handled before any other messages that are later sent to the
225 * isolate from the current isolate, but no other guarantees are provided. 254 * isolate from the current isolate, but no other guarantees are provided.
226 * 255 *
227 * The event loop may be paused before previously sent, but not yet exeuted, 256 * The event loop may be paused before previously sent, but not yet exeuted,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 * thing before it terminates. It will run no further code after the message 298 * thing before it terminates. It will run no further code after the message
270 * has been sent. 299 * has been sent.
271 * 300 *
272 * Adding the same port more than once will only cause it to receive one 301 * Adding the same port more than once will only cause it to receive one
273 * message, using the last response value that was added. 302 * message, using the last response value that was added.
274 * 303 *
275 * If the isolate is already dead, no message will be sent. 304 * If the isolate is already dead, no message will be sent.
276 * If `response` cannot be sent to the isolate, then the request is ignored. 305 * If `response` cannot be sent to the isolate, then the request is ignored.
277 * It is recommended to only use simple values that can be sent to all 306 * It is recommended to only use simple values that can be sent to all
278 * isolates, like `null`, booleans, numbers or strings. 307 * isolates, like `null`, booleans, numbers or strings.
279 * 308 *
280 * Since isolates run concurrently, it's possible for it to exit before the 309 * Since isolates run concurrently, it's possible for it to exit before the
281 * exit listener is established. To avoid this, start the isolate paused, 310 * exit listener is established, and in that case no response will be
282 * add the listener, then resume it. 311 * sent on [responsePort].
312 * To avoid this, either use the corresponding parameter to the spawn
313 * function, or start the isolate paused, add the listener and
314 * then resume the isolate.
283 */ 315 */
284 /* TODO(lrn): Can we do better? Can the system recognize this message and 316 /* TODO(lrn): Can we do better? Can the system recognize this message and
285 * send a reply if the receiving isolate is dead? 317 * send a reply if the receiving isolate is dead?
286 */ 318 */
287 external void addOnExitListener(SendPort responsePort, {Object response}); 319 external void addOnExitListener(SendPort responsePort, {Object response});
288 320
289 /** 321 /**
290 * Stop listening on exit messages from the isolate. 322 * Stop listening on exit messages from the isolate.
291 * 323 *
292 * If a call has previously been made to [addOnExitListener] with the same 324 * If a call has previously been made to [addOnExitListener] with the same
293 * send-port, this will unregister the port, and it will no longer receive 325 * send-port, this will unregister the port, and it will no longer receive
294 * a message when the isolate terminates. 326 * a message when the isolate terminates.
295 * A response may still be sent until this operation is fully processed by 327 * A response may still be sent until this operation is fully processed by
296 * the isolate. 328 * the isolate.
297 */ 329 */
298 external void removeOnExitListener(SendPort responsePort); 330 external void removeOnExitListener(SendPort responsePort);
299 331
300 /** 332 /**
301 * Set whether uncaught errors will terminate the isolate. 333 * Set whether uncaught errors will terminate the isolate.
302 * 334 *
303 * If errors are fatal, any uncaught error will terminate the isolate 335 * If errors are fatal, any uncaught error will terminate the isolate
304 * event loop and shut down the isolate. 336 * event loop and shut down the isolate.
305 * 337 *
306 * This call requires the [terminateCapability] for the isolate. 338 * This call requires the [terminateCapability] for the isolate.
307 * If the capability is not correct, no change is made. 339 * If the capability is not correct, no change is made.
340 *
341 * Since isolates run concurrently, it's possible for it to exit due to an
342 * error before errors are set non-fatal.
343 * To avoid this, either use the corresponding parameter to the spawn
344 * function, or start the isolate paused, set errors non-fatal and
345 * then resume the isolate.
308 */ 346 */
309 external void setErrorsFatal(bool errorsAreFatal); 347 external void setErrorsFatal(bool errorsAreFatal);
310 348
311 /** 349 /**
312 * Requests the isolate to shut down. 350 * Requests the isolate to shut down.
313 * 351 *
314 * The isolate is requested to terminate itself. 352 * The isolate is requested to terminate itself.
315 * The [priority] argument specifies when this must happen. 353 * The [priority] argument specifies when this must happen.
316 * 354 *
317 * The [priority] must be one of [IMMEDIATE] or [BEFORE_NEXT_EVENT]. 355 * The [priority] must be one of [IMMEDIATE] or [BEFORE_NEXT_EVENT].
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 * 399 *
362 * The errors are sent back as two elements lists. 400 * The errors are sent back as two elements lists.
363 * The first element is a `String` representation of the error, usually 401 * The first element is a `String` representation of the error, usually
364 * created by calling `toString` on the error. 402 * created by calling `toString` on the error.
365 * The second element is a `String` representation of an accompanying 403 * The second element is a `String` representation of an accompanying
366 * stack trace, or `null` if no stack trace was provided. 404 * stack trace, or `null` if no stack trace was provided.
367 * To convert this back to a [StackTrace] object, use [StackTrace.fromString]. 405 * To convert this back to a [StackTrace] object, use [StackTrace.fromString].
368 * 406 *
369 * Listening using the same port more than once does nothing. It will only 407 * Listening using the same port more than once does nothing. It will only
370 * get each error once. 408 * get each error once.
371 * 409 *
372 * Since isolates run concurrently, it's possible for it to exit before the 410 * Since isolates run concurrently, it's possible for it to exit before the
373 * error listener is established. To avoid this, start the isolate paused, 411 * error listener is established. To avoid this, start the isolate paused,
374 * add the listener, then resume it. 412 * add the listener and then resume the isolate.
375 */ 413 */
376 external void addErrorListener(SendPort port); 414 external void addErrorListener(SendPort port);
377 415
378 /** 416 /**
379 * Stop listening for uncaught errors through [port]. 417 * Stop listening for uncaught errors through [port].
380 * 418 *
381 * The `port` should be a port that is listening for errors through 419 * The `port` should be a port that is listening for errors through
382 * [addErrorListener]. This call requests that the isolate stops sending 420 * [addErrorListener]. This call requests that the isolate stops sending
383 * errors on the port. 421 * errors on the port.
384 * 422 *
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 * as the original error, but has no other features of the original error. 636 * as the original error, but has no other features of the original error.
599 */ 637 */
600 class RemoteError implements Error { 638 class RemoteError implements Error {
601 final String _description; 639 final String _description;
602 final StackTrace stackTrace; 640 final StackTrace stackTrace;
603 RemoteError(String description, String stackDescription) 641 RemoteError(String description, String stackDescription)
604 : _description = description, 642 : _description = description,
605 stackTrace = new StackTrace.fromString(stackDescription); 643 stackTrace = new StackTrace.fromString(stackDescription);
606 String toString() => _description; 644 String toString() => _description;
607 } 645 }
OLDNEW
« 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