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

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

Issue 9422019: isolates refactor: this change introduces 'dart:isolate' as a library. This is a (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 // Dart core library.
6 // TODO(sigmund): move to dart:isolate
7
8 /** 5 /**
9 * [SendPort]s are created from [ReceivePort]s. Any message sent through 6 * [SendPort]s are created from [ReceivePort]s. Any message sent through
10 * a [SendPort] is delivered to its respective [ReceivePort]. There might be 7 * a [SendPort] is delivered to its respective [ReceivePort]. There might be
11 * many [SendPort]s for the same [ReceivePort]. 8 * many [SendPort]s for the same [ReceivePort].
12 * 9 *
13 * [SendPort]s can be transmitted to other isolates. 10 * [SendPort]s can be transmitted to other isolates.
14 */ 11 */
15 interface SendPort extends Hashable { 12 interface SendPort extends Hashable {
16 13
17 /** 14 /**
(...skipping 30 matching lines...) Expand all
48 45
49 /** 46 /**
50 * [ReceivePort]s, together with [SendPort]s, are the only means of 47 * [ReceivePort]s, together with [SendPort]s, are the only means of
51 * communication between isolates. [ReceivePort]s have a [:toSendPort:] method 48 * communication between isolates. [ReceivePort]s have a [:toSendPort:] method
52 * which returns a [SendPort]. Any message that is sent through this [SendPort] 49 * which returns a [SendPort]. Any message that is sent through this [SendPort]
53 * is delivered to the [ReceivePort] it has been created from. There, they are 50 * is delivered to the [ReceivePort] it has been created from. There, they are
54 * dispatched to the callback that has been registered on the receive port. 51 * dispatched to the callback that has been registered on the receive port.
55 * 52 *
56 * A [ReceivePort] may have many [SendPort]s. 53 * A [ReceivePort] may have many [SendPort]s.
57 */ 54 */
58 interface ReceivePort default ReceivePortFactory { 55 interface ReceivePort default _ReceivePortFactory {
59 56
60 /** 57 /**
61 * Opens a long-lived port for receiving messages. The returned port 58 * Opens a long-lived port for receiving messages. The returned port
62 * must be explicitly closed through [ReceivePort.close]. 59 * must be explicitly closed through [ReceivePort.close].
63 */ 60 */
64 ReceivePort(); 61 ReceivePort();
65 62
66 /** 63 /**
67 * Opens a single-shot reply port. Once a message has been received 64 * Opens a single-shot reply port. Once a message has been received
68 * on this port, it is automatically closed -- obviously without 65 * on this port, it is automatically closed -- obviously without
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 * inside the new isolate and stored in the read-only field [port]. 137 * inside the new isolate and stored in the read-only field [port].
141 * A corresponding [SendPort] is sent to the isolate that invoked [spawn]. 138 * A corresponding [SendPort] is sent to the isolate that invoked [spawn].
142 * Since spawning an isolate is an asynchronous operation this method returns 139 * Since spawning an isolate is an asynchronous operation this method returns
143 * a [Future] of this [SendPort]. 140 * a [Future] of this [SendPort].
144 * 141 *
145 * A common pattern to instantiate new isolates is to enqueue the instructions 142 * A common pattern to instantiate new isolates is to enqueue the instructions
146 * using [Future.then]. 143 * using [Future.then].
147 * [:myIsolate.spawn().then((SendPort port) { port.send('hi there'); });:] 144 * [:myIsolate.spawn().then((SendPort port) { port.send('hi there'); });:]
148 */ 145 */
149 Future<SendPort> spawn() { 146 Future<SendPort> spawn() {
150 return IsolateNatives.spawn(this, _isLight); 147 return _IsolateNatives.spawn(this, _isLight);
151 } 148 }
152 149
153 // The private run method is invoked with the receive port. Before 150 // The private run method is invoked with the receive port. Before
154 // main is invoked we store the port in a field so it can be 151 // main is invoked we store the port in a field so it can be
155 // accessed from subclasses of Isolate. 152 // accessed from subclasses of Isolate.
156 void _run(ReceivePort port) { 153 void _run(ReceivePort port) {
157 _port = port; 154 _port = port;
158 main(); 155 main();
159 } 156 }
160 157
(...skipping 12 matching lines...) Expand all
173 /** 170 /**
174 * When isolates are created, an instance of the template's class is 171 * When isolates are created, an instance of the template's class is
175 * instantiated in the new isolate. After the [port] has been set up, this 172 * instantiated in the new isolate. After the [port] has been set up, this
176 * [main] method is invoked on the instance. 173 * [main] method is invoked on the instance.
177 */ 174 */
178 abstract void main(); 175 abstract void main();
179 176
180 final bool _isLight; 177 final bool _isLight;
181 ReceivePort _port; 178 ReceivePort _port;
182 } 179 }
180
181 /**
182 * [Isolate2] provides APIs to spawn, communicate, and stop an isolate. An
183 * isolate can be spawned by simply creating a new instance of [Isolate2]. The
184 * [Isolate2] instance exposes a port to communicate with the isolate and
185 * methods to control its behavior remotely.
186 */
187 // TODO(sigmund): rename to Isolate once we delete the old implementation
188 interface Isolate2 default _IsolateFactory {
189
190 /**
191 * Create and spawn an isolate that shares the same code as the current
192 * isolate, but that starts from [topLevelFunction]. The [topLevelFunction]
193 * argument must be a static method closure that takes exactly one
194 * argument of type [ReceivePort]. It is illegal to pass a function closure
195 * that captures values in scope.
196 *
197 * When an child isolate is spawned, a new [ReceivePort] is created for it.
198 * This port is passed to [topLevelFunction]. A [SendPort] derived from
199 * such port is sent to the spawner isolate, which is accessible in
200 * [Isolate2.sendPort] field of this instance.
201 */
202 Isolate2.fromCode(Function topLevelFunction);
203
204 /**
205 * Create and spawn an isolate whose code is available at [uri].
206 * The code in [uri] must have an method called [: isolateMain :], which takes
207 * exactly one argument of type [ReceivePort].
208 * Like with [Isolate2.fromCode], a [ReceivePort] is created in the child
209 * isolate, and a [SendPort] to it is stored in [Isolate2.sendPort].
210 */
211 Isolate2.fromUri(String uri);
212
213 /** Port used to communicate with this isolate. */
214 SendPort sendPort;
215 }
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