OLD | NEW |
---|---|
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 | |
216 /** Stop this isolate. */ | |
217 void stop(); | |
siva
2012/02/22 00:58:20
What is the semantics of this stop? Could you docu
Siggi Cherem (dart-lang)
2012/02/22 19:18:50
This is something that we were planning to remove,
| |
218 } | |
OLD | NEW |