Chromium Code Reviews| Index: sdk/lib/isolate/isolate.dart |
| diff --git a/sdk/lib/isolate/isolate.dart b/sdk/lib/isolate/isolate.dart |
| index 49c0eb82b6ec79a044575f47a495bd079713d570..c9593d30015b8d3498cebb6282e5fb9630126a50 100644 |
| --- a/sdk/lib/isolate/isolate.dart |
| +++ b/sdk/lib/isolate/isolate.dart |
| @@ -6,7 +6,20 @@ library dart.isolate; |
| import "dart:async"; |
| -part "isolate_stream.dart"; |
| +/** |
| + * Returns the initial message an isolate received. |
| + * |
| + * If the isolate is the main-isolate it contains the list of arguments that |
| + * have been given on the command line. |
| + * |
| + * This getter supercedes io:Options (which is now deprecated). |
| + */ |
| +// TODO(floitsch): alternatively we could keep io:Options (or a nicer variant |
| +// of it). The main advantage of removing it, is that libraries/programs that |
| +// are otherwise server-independent could be spawned in the browser. |
| +// If devs use dart:io just for the arguments they can't be used in spawnUri, |
| +// by forcing them to use dart:isolate they would run in the browser, too. |
| +dynamic get isolateMessage; |
|
Lasse Reichstein Nielsen
2013/08/26 08:06:06
Another global variable.
Can we please just pass
|
| class IsolateSpawnException implements Exception { |
| const IsolateSpawnException(String this._s); |
| @@ -15,41 +28,23 @@ class IsolateSpawnException implements Exception { |
| } |
| /** |
| - * The initial [ReceivePort] available by default for this isolate. This |
| - * [ReceivePort] is created automatically and it is commonly used to establish |
| - * the first communication between isolates (see [spawnFunction] and |
| - * [spawnUri]). |
| - */ |
| -ReceivePort get port => _Isolate.port; |
| - |
| -/** |
| * Creates and spawns an isolate that shares the same code as the current |
| * isolate, but that starts from [topLevelFunction]. The [topLevelFunction] |
| * argument must be a static top-level function or a static method that takes no |
| * arguments. It is illegal to pass a function closure. |
| * |
| - * When any isolate starts (even the main script of the application), a default |
| - * [ReceivePort] is created for it. This port is available from the top-level |
| - * getter [port] defined in this library. |
| - * |
| - * [spawnFunction] returns a [SendPort] derived from the child isolate's default |
| - * port. |
| - * |
| - * The optional [unhandledExceptionCallback] argument is invoked whenever an |
| - * exception inside the isolate is unhandled. It can be seen as a big |
| - * `try/catch` around everything that is executed inside the isolate. The |
| - * callback should return `true` when it was able to handled the exception. |
| + * The initial [message] is stored in the global [isolateMessage] where the |
| + * spawnee can access it. Usually the initial [message] contains a [SendPort] so |
| + * that the spawner and spawnee can communicate with each other. |
| */ |
| -SendPort spawnFunction(void topLevelFunction(), |
| - [bool unhandledExceptionCallback(IsolateUnhandledException e)]) |
| - => _Isolate.spawnFunction(topLevelFunction, unhandledExceptionCallback); |
| +void spawnFunction(void topLevelFunction(), [dynamic message]); |
| /** |
| - * Creates and spawns an isolate whose code is available at [uri]. Like with |
| - * [spawnFunction], the child isolate will have a default [ReceivePort], and a |
| - * this function returns a [SendPort] derived from it. |
| + * Creates and spawns an isolate whose code is available at [uri]. |
| + * |
| + * Otherwise similar to [spawnFunction]. |
| */ |
| -SendPort spawnUri(String uri) => _Isolate.spawnUri(uri); |
| +void spawnUri(Uri uri, [dynamic message]); |
|
Lasse Reichstein Nielsen
2013/08/26 08:06:06
Make it possible for this call to pass at least
-
|
| /** |
| * [SendPort]s are created from [ReceivePort]s. Any message sent through |
| @@ -69,6 +64,11 @@ abstract class SendPort { |
| * String), instances of [SendPort], and lists and maps whose elements are any |
| * of these. List and maps are also allowed to be cyclic. |
| * |
| + * If, during serialization, an object of different type (then the primitive |
| + * values mentioned above) is encountered, the |
| + * serializer (if given) is invoked. TODO(floitsch): specify how |
| + * serialization and deserialization should work. |
| + * |
| * In the special circumstances when two isolates share the same code and are |
| * running in the same process (e.g. isolates created via [spawnFunction]), it |
| * is also possible to send object instances (which would be copied in the |
| @@ -79,7 +79,12 @@ abstract class SendPort { |
| * message. Previously they were translated to the corresponding send port |
| * before being transmitted. |
| */ |
| - void send(var message, [SendPort replyTo]); |
| + // We could allow a named deserializer argument which must be a global |
| + // function (just like for spawnFunction) and could be transmitted (again, |
| + // like for spawnFunction). This way the receiver wouldn't need to know |
| + // how to deserialize. |
| + // void send(var message, { serializer(x), deserializer(x), SendPort replyTo }); |
| + void send(var message, { serializer(x), SendPort replyTo }); |
| /** |
| * Sends a message to this send port and returns a [Future] of the reply. |
| @@ -87,6 +92,9 @@ abstract class SendPort { |
| * message to this send port with replyTo set to such receive port, and, when |
| * a reply is received, it closes the receive port and completes the returned |
| * future. |
| + * |
| + * Note: it is not possible to provide a serializer to this function. Use |
| + * [send] instead. |
| */ |
| Future call(var message); |
| @@ -118,14 +126,17 @@ abstract class ReceivePort { |
| /** |
| * Opens a long-lived port for receiving messages. The returned port |
| * must be explicitly closed through [ReceivePort.close]. |
| + * |
| + * If a message was serialized during sending the deserializer is invoked |
| + * when receiving data. |
| */ |
| - external factory ReceivePort(); |
| + external factory ReceivePort({ deserializer(x) }); |
| /** |
| * Sets up a callback function for receiving pending or future |
| * messages on this receive port. |
| */ |
| - void receive(void callback(var message, SendPort replyTo)); |
| + void onData(void callback(var message, SendPort replyTo)); |
| /** |
| * Closes this receive port immediately. Pending messages will not |