| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 class IsolateSpawnException implements Exception { | |
| 6 const IsolateSpawnException(String this._s); | |
| 7 String toString() => "IsolateSpawnException: '$_s'"; | |
| 8 final String _s; | |
| 9 } | |
| 10 | |
| 11 /** | |
| 12 * The initial [ReceivePort] available by default for this isolate. This | |
| 13 * [ReceivePort] is created automatically and it is commonly used to establish | |
| 14 * the first communication between isolates (see [spawnFunction] and | |
| 15 * [spawnUri]). | |
| 16 */ | |
| 17 external ReceivePort get port(); | |
| 18 | |
| 19 /** | |
| 20 * Creates and spawns an isolate that shares the same code as the current | |
| 21 * isolate, but that starts from [topLevelFunction]. The [topLevelFunction] | |
| 22 * argument must be a static top-level function or a static method that takes no | |
| 23 * arguments. It is illegal to pass a function closure. | |
| 24 * | |
| 25 * When any isolate starts (even the main script of the application), a default | |
| 26 * [ReceivePort] is created for it. This port is available from the top-level | |
| 27 * getter [port] defined in this library. | |
| 28 * | |
| 29 * [spawnFunction] returns a [SendPort] derived from the child isolate's default | |
| 30 * port. | |
| 31 * | |
| 32 * See comments at the top of this library for more details. | |
| 33 */ | |
| 34 // Note this feature is not yet available in the dartvm. | |
| 35 external SendPort spawnFunction(void topLevelFunction()); | |
| 36 | |
| 37 /** | |
| 38 * Creates and spawns an isolate whose code is available at [uri]. Like with | |
| 39 * [spawnFunction], the child isolate will have a default [ReceivePort], and a | |
| 40 * this function returns a [SendPort] derived from it. | |
| 41 * | |
| 42 * See comments at the top of this library for more details. | |
| 43 */ | |
| 44 external SendPort spawnUri(String uri); | |
| 45 | |
| 46 /** | |
| 47 * [SendPort]s are created from [ReceivePort]s. Any message sent through | |
| 48 * a [SendPort] is delivered to its respective [ReceivePort]. There might be | |
| 49 * many [SendPort]s for the same [ReceivePort]. | |
| 50 * | |
| 51 * [SendPort]s can be transmitted to other isolates. | |
| 52 */ | |
| 53 interface SendPort extends Hashable { | |
| 54 | |
| 55 /** | |
| 56 * Sends an asynchronous [message] to this send port. The message is copied to | |
| 57 * the receiving isolate. If specified, the [replyTo] port will be provided to | |
| 58 * the receiver to facilitate exchanging sequences of messages. | |
| 59 * | |
| 60 * The content of [message] can be: primitive values (null, num, bool, double, | |
| 61 * String), instances of [SendPort], and lists and maps whose elements are any | |
| 62 * of these. List and maps are also allowed to be cyclic. | |
| 63 * | |
| 64 * In the special circumstances when two isolates share the same code and are | |
| 65 * running in the same process (e.g. isolates created via [spawnFunction]), it | |
| 66 * is also possible to send object instances (which would be copied in the | |
| 67 * process). This is currently only supported by the dartvm. For now, the | |
| 68 * frog compiler only supports the restricted messages described above. | |
| 69 * | |
| 70 * Deprecation note: it is no longer valid to transmit a [ReceivePort] in a | |
| 71 * message. Previously they were translated to the corresponding send port | |
| 72 * before being transmitted. | |
| 73 */ | |
| 74 void send(var message, [SendPort replyTo]); | |
| 75 | |
| 76 /** | |
| 77 * Sends a message to this send port and returns a [Future] of the reply. | |
| 78 * Basically, this internally creates a new receive port, sends a | |
| 79 * message to this send port with replyTo set to such receive port, and, when | |
| 80 * a reply is received, it closes the receive port and completes the returned | |
| 81 * future. | |
| 82 */ | |
| 83 Future call(var message); | |
| 84 | |
| 85 /** | |
| 86 * Tests whether [other] is a [SendPort] pointing to the same | |
| 87 * [ReceivePort] as this one. | |
| 88 */ | |
| 89 bool operator==(var other); | |
| 90 | |
| 91 /** | |
| 92 * Returns an immutable hash code for this send port that is | |
| 93 * consistent with the == operator. | |
| 94 */ | |
| 95 int hashCode(); | |
| 96 | |
| 97 } | |
| 98 | |
| 99 /** | |
| 100 * [ReceivePort]s, together with [SendPort]s, are the only means of | |
| 101 * communication between isolates. [ReceivePort]s have a [:toSendPort:] method | |
| 102 * which returns a [SendPort]. Any message that is sent through this [SendPort] | |
| 103 * is delivered to the [ReceivePort] it has been created from. There, they are | |
| 104 * dispatched to the callback that has been registered on the receive port. | |
| 105 * | |
| 106 * A [ReceivePort] may have many [SendPort]s. | |
| 107 */ | |
| 108 interface ReceivePort default _ReceivePortFactory { | |
| 109 | |
| 110 /** | |
| 111 * Opens a long-lived port for receiving messages. The returned port | |
| 112 * must be explicitly closed through [ReceivePort.close]. | |
| 113 */ | |
| 114 ReceivePort(); | |
| 115 | |
| 116 /** | |
| 117 * Sets up a callback function for receiving pending or future | |
| 118 * messages on this receive port. | |
| 119 */ | |
| 120 void receive(void callback(var message, SendPort replyTo)); | |
| 121 | |
| 122 /** | |
| 123 * Closes this receive port immediately. Pending messages will not | |
| 124 * be processed and it is impossible to re-open the port. Single-shot | |
| 125 * reply ports, such as those created through [SendPort.call], are | |
| 126 * automatically closed when the reply has been received. Multiple | |
| 127 * invocations of [close] are allowed but ignored. | |
| 128 */ | |
| 129 void close(); | |
| 130 | |
| 131 /** | |
| 132 * Creates a new send port that sends to this receive port. It is legal to | |
| 133 * create several [SendPort]s from the same [ReceivePort]. | |
| 134 */ | |
| 135 SendPort toSendPort(); | |
| 136 | |
| 137 } | |
| 138 | |
| 139 // TODO(kasperl): Make this hashable and document it. | |
| 140 interface SendPortSync { | |
| 141 | |
| 142 callSync(var message); | |
| 143 | |
| 144 } | |
| 145 | |
| 146 class _ReceivePortFactory { | |
| 147 external factory ReceivePort(); | |
| 148 } | |
| OLD | NEW |