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

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

Issue 9652001: SendPort + ReceivePort changes: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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 | « lib/isolate/frog/ports.dart ('k') | lib/isolate/isolate_compiler.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 * The initial [ReceivePort] available by default for this isolate. This 6 * The initial [ReceivePort] available by default for this isolate. This
7 * [ReceivePort] is created automatically and it is commonly used to establish 7 * [ReceivePort] is created automatically and it is commonly used to establish
8 * the first communication between isolates (see [spawnFunction] and 8 * the first communication between isolates (see [spawnFunction] and
9 * [spawnUri]). 9 * [spawnUri]).
10 */ 10 */
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 /** 44 /**
45 * [SendPort]s are created from [ReceivePort]s. Any message sent through 45 * [SendPort]s are created from [ReceivePort]s. Any message sent through
46 * a [SendPort] is delivered to its respective [ReceivePort]. There might be 46 * a [SendPort] is delivered to its respective [ReceivePort]. There might be
47 * many [SendPort]s for the same [ReceivePort]. 47 * many [SendPort]s for the same [ReceivePort].
48 * 48 *
49 * [SendPort]s can be transmitted to other isolates. 49 * [SendPort]s can be transmitted to other isolates.
50 */ 50 */
51 interface SendPort extends Hashable { 51 interface SendPort extends Hashable {
52 52
53 /** 53 /**
54 * Sends an asynchronous [message] to this send port. The message is 54 * Sends an asynchronous [message] to this send port. The message is copied to
55 * copied to the receiving isolate. If the message contains any 55 * the receiving isolate. If specified, the [replyTo] port will be provided to
56 * receive ports, they are translated to the corresponding send port 56 * the receiver to facilitate exchanging sequences of messages.
57 * before being transmitted. If specified, the [replyTo] port will be 57 *
58 * provided to the receiver to facilitate exchanging sequences of 58 * The content of [message] can be: primitive values (null, num, bool, double,
59 * messages. 59 * String), instances of [SendPort], and lists and maps whose elements are any
60 * of these. List and maps are also allowed to be cyclic.
61 *
62 * In the special circumstances when two isolates share the same code and are
63 * running in the same process (e.g. isolates created via [spawnFunction]), it
64 * is also possible to send object instances (which would be copied in the
65 * process). This is currently only supported by the dartvm. For now, the
66 * frog compiler only supports the restricted messages described above.
67 *
68 * Deprecation note: it is no longer valid to transmit a [ReceivePort] in a
69 * message. Previously they were translated to the corresponding send port
70 * before being transmitted.
60 */ 71 */
61 void send(var message, [SendPort replyTo]); 72 void send(var message, [SendPort replyTo]);
62 73
63 /** 74 /**
64 * Creates a new single-shot receive port, sends a message to this 75 * Sends a message to this send port and returns a [Future] of the reply.
65 * send port with replyTo set to the opened port, and returns the 76 * Basically, this internally creates a new receive port, sends a
66 * receive port. 77 * message to this send port with replyTo set to such receive port, and, when
78 * a reply is received, it closes the receive port and completes the returned
79 * future.
67 */ 80 */
68 ReceivePort call(var message); 81 Future call(var message);
69 82
70 /** 83 /**
71 * Tests whether [other] is a [SendPort] pointing to the same 84 * Tests whether [other] is a [SendPort] pointing to the same
72 * [ReceivePort] as this one. 85 * [ReceivePort] as this one.
73 */ 86 */
74 bool operator==(var other); 87 bool operator==(var other);
75 88
76 /** 89 /**
77 * Returns an immutable hash code for this send port that is 90 * Returns an immutable hash code for this send port that is
78 * consistent with the == operator. 91 * consistent with the == operator.
(...skipping 13 matching lines...) Expand all
92 */ 105 */
93 interface ReceivePort default _ReceivePortFactory { 106 interface ReceivePort default _ReceivePortFactory {
94 107
95 /** 108 /**
96 * Opens a long-lived port for receiving messages. The returned port 109 * Opens a long-lived port for receiving messages. The returned port
97 * must be explicitly closed through [ReceivePort.close]. 110 * must be explicitly closed through [ReceivePort.close].
98 */ 111 */
99 ReceivePort(); 112 ReceivePort();
100 113
101 /** 114 /**
102 * Opens a single-shot reply port. Once a message has been received
103 * on this port, it is automatically closed -- obviously without
104 * throwing the message away before it can be processed. This
105 * constructor is used indirectly through [SendPort.call].
106 */
107 ReceivePort.singleShot();
108
109 /**
110 * Sets up a callback function for receiving pending or future 115 * Sets up a callback function for receiving pending or future
111 * messages on this receive port. 116 * messages on this receive port.
112 */ 117 */
113 void receive(void callback(var message, SendPort replyTo)); 118 void receive(void callback(var message, SendPort replyTo));
114 119
115 /** 120 /**
116 * Closes this receive port immediately. Pending messages will not 121 * Closes this receive port immediately. Pending messages will not
117 * be processed and it is impossible to re-open the port. Single-shot 122 * be processed and it is impossible to re-open the port. Single-shot
118 * reply ports, such as those created through [SendPort.call], are 123 * reply ports, such as those created through [SendPort.call], are
119 * automatically closed when the reply has been received. Multiple 124 * automatically closed when the reply has been received. Multiple
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 /** 221 /**
217 * When isolates are created, an instance of the template's class is 222 * When isolates are created, an instance of the template's class is
218 * instantiated in the new isolate. After the [port] has been set up, this 223 * instantiated in the new isolate. After the [port] has been set up, this
219 * [main] method is invoked on the instance. 224 * [main] method is invoked on the instance.
220 */ 225 */
221 abstract void main(); 226 abstract void main();
222 227
223 final bool _isLight; 228 final bool _isLight;
224 ReceivePort _port; 229 ReceivePort _port;
225 } 230 }
OLDNEW
« no previous file with comments | « lib/isolate/frog/ports.dart ('k') | lib/isolate/isolate_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698