OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 * Concurrent programming using _isolates_: | 6 * Concurrent programming using _isolates_: |
7 * independent workers that are similar to threads | 7 * independent workers that are similar to threads |
8 * but don't share memory, | 8 * but don't share memory, |
9 * communicating only via messages. | 9 * communicating only via messages. |
10 * | 10 * |
11 * To use this library in your code: | 11 * To use this library in your code: |
12 * | 12 * |
13 * import 'dart:isolate'; | 13 * import 'dart:isolate'; |
14 */ | 14 */ |
15 library dart.isolate; | 15 library dart.isolate; |
16 | 16 |
17 import "dart:async"; | 17 import "dart:async"; |
18 | 18 |
19 part "capability.dart"; | 19 part "capability.dart"; |
20 | 20 |
21 /** | 21 /** |
22 * Thrown when an isolate cannot be created. | 22 * Thrown when an isolate cannot be created. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 * If there is no valid mapping from the package: URI in the current | 155 * If there is no valid mapping from the package: URI in the current |
156 * isolate, then this call returns `null`. Non-package: URIs are | 156 * isolate, then this call returns `null`. Non-package: URIs are |
157 * returned unmodified. | 157 * returned unmodified. |
158 */ | 158 */ |
159 external static Future<Uri> resolvePackageUri(Uri packageUri); | 159 external static Future<Uri> resolvePackageUri(Uri packageUri); |
160 | 160 |
161 /** | 161 /** |
162 * Creates and spawns an isolate that shares the same code as the current | 162 * Creates and spawns an isolate that shares the same code as the current |
163 * isolate. | 163 * isolate. |
164 * | 164 * |
165 * The argument [entryPoint] specifies the entry point of the spawned | 165 * The argument [entryPoint] specifies the initial function to call |
166 * isolate. It must be a top-level function or a static method that | 166 * in the spawned isolate. |
167 * takes one argument - that is, one-parameter functions that can be | 167 * The entry-point function is invoked in the new isolate with [message] |
168 * compile-time constant function values. | 168 * as the only argument. |
169 * It is not allowed to pass the value of function expressions or an instance | |
170 * method extracted from an object. | |
171 * | 169 * |
172 * The entry-point function is invoked with the initial [message]. | 170 * The function must be a top-level function or a static method |
171 * that can be called with a single argument - | |
eernst
2016/06/14 11:36:47
Might as well use ',' because the single hyphen is
Lasse Reichstein Nielsen
2016/07/04 11:47:32
Done.
| |
172 * that is, a compile-time constant function value | |
173 * which accepts at least one positional parameter | |
174 * and has at most one required positional parameter. | |
175 * The function may accept any number of optional parameters, | |
176 * as long as they *can* be called with just a single argument. | |
eernst
2016/06/14 11:36:47
There's a singular/plural issue here, and I also t
Lasse Reichstein Nielsen
2016/07/04 11:47:33
Done.
| |
177 * The value of a function expressions or a torn-off instance methods are not | |
178 * allowed. | |
eernst
2016/06/14 11:36:47
A bit of confusion here, too. Maybe it would work
Lasse Reichstein Nielsen
2016/07/04 11:47:33
You can't pass an expression, only its value.
Rewo
| |
179 * | |
173 * Usually the initial [message] contains a [SendPort] so | 180 * Usually the initial [message] contains a [SendPort] so |
174 * that the spawner and spawnee can communicate with each other. | 181 * that the spawner and spawnee can communicate with each other. |
175 * | 182 * |
176 * If the [paused] parameter is set to `true`, | 183 * If the [paused] parameter is set to `true`, |
177 * the isolate will start up in a paused state, | 184 * the isolate will start up in a paused state, |
185 * just before calling the [entryPoint] function with the [message], | |
178 * as if by an initial call of `isolate.pause(isolate.pauseCapability)`. | 186 * as if by an initial call of `isolate.pause(isolate.pauseCapability)`. |
179 * To resume the isolate, call `isolate.resume(isolate.pauseCapability)`. | 187 * To resume the isolate, call `isolate.resume(isolate.pauseCapability)`. |
180 * | 188 * |
181 * If the [errorAreFatal], [onExit] and/or [onError] parameters are provided, | 189 * If the [errorAreFatal], [onExit] and/or [onError] parameters are provided, |
182 * the isolate will act as if, respectively, [setErrorsFatal], | 190 * the isolate will act as if, respectively, [setErrorsFatal], |
183 * [addOnExitListener] and [addErrorListener] were called with the | 191 * [addOnExitListener] and [addErrorListener] were called with the |
184 * corresponding parameter and was processed before the isolate starts | 192 * corresponding parameter and was processed before the isolate starts |
185 * running. | 193 * running. |
186 * | 194 * |
195 * If [errorsAreFatal] is omitted, the platform may choose a default behavior | |
196 * or inherit the current isolate's behavior. | |
197 * | |
187 * You can also call the [setErrorsFatal], [addOnExitListener] and | 198 * You can also call the [setErrorsFatal], [addOnExitListener] and |
188 * [addErrorListener] methods on the returned isolate, but unless the | 199 * [addErrorListener] methods on the returned isolate, but unless the |
189 * isolate was started as [paused], it may already have terminated | 200 * isolate was started as [paused], it may already have terminated |
190 * before those methods can complete. | 201 * before those methods can complete. |
191 * | 202 * |
192 * Returns a future that will complete with an [Isolate] instance if the | 203 * Returns a future which will complete with an [Isolate] instance if the |
193 * spawning succeeded. It will complete with an error otherwise. | 204 * spawning succeeded. It will complete with an error otherwise. |
194 */ | 205 */ |
195 external static Future<Isolate> spawn(void entryPoint(message), var message, | 206 external static Future<Isolate> spawn(void entryPoint(message), var message, |
196 { bool paused: false, | 207 {bool paused: false, |
197 bool errorsAreFatal, | 208 bool errorsAreFatal, |
198 SendPort onExit, | 209 SendPort onExit, |
199 SendPort onError }); | 210 SendPort onError}); |
200 | 211 |
201 /** | 212 /** |
202 * Creates and spawns an isolate that runs the code from the library with | 213 * Creates and spawns an isolate that runs the code from the library with |
203 * the specified URI. | 214 * the specified URI. |
204 * | 215 * |
205 * The isolate starts executing the top-level `main` function of the library | 216 * The isolate starts executing the top-level `main` function of the library |
206 * with the given URI. | 217 * with the given URI. |
207 * | 218 * |
208 * The target `main` must be callable with zero, one or two arguments. | 219 * The target `main` must be callable with zero, one or two arguments. |
209 * Examples: | 220 * Examples: |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 bool errorsAreFatal, | 295 bool errorsAreFatal, |
285 bool checked, | 296 bool checked, |
286 Map<String, String> environment, | 297 Map<String, String> environment, |
287 Uri packageRoot, | 298 Uri packageRoot, |
288 Uri packageConfig, | 299 Uri packageConfig, |
289 bool automaticPackageResolution: false}); | 300 bool automaticPackageResolution: false}); |
290 | 301 |
291 /** | 302 /** |
292 * Requests the isolate to pause. | 303 * Requests the isolate to pause. |
293 * | 304 * |
294 * The isolate should stop handling events by pausing its event queue. | 305 * When the isolate receives the pause command, it will stop |
floitsch
2016/06/16 08:36:34
Stops
Lasse Reichstein Nielsen
2016/07/04 11:47:33
Done.
| |
295 * The request will eventually make the isolate stop doing anything. | 306 * processing events from the event loop queue. |
296 * It will be handled before any other messages that are later sent to the | 307 * It may still add new events to the queue in response to, e.g., timers |
297 * isolate from the current isolate, but no other guarantees are provided. | 308 * or receive port messages. When the isolate is resumed, it will handle |
floitsch
2016/06/16 08:36:35
Maybe "handles" but here it really is in the futur
Lasse Reichstein Nielsen
2016/07/04 11:47:32
Used "handles" and improved the second half of the
| |
309 * the enqueued events in the order they were enqueued. | |
298 * | 310 * |
299 * The event loop may be paused before previously sent, but not yet exeuted, | 311 * The pause request is sent through the isolate's command port and will be |
300 * messages have been reached. | 312 * handled when it is received, after other previously sent command messages, |
313 * but before already enqueued event loop events that hasn't been processed | |
eernst
2016/06/14 11:36:47
'after any previously sent command messages, but b
Lasse Reichstein Nielsen
2016/07/04 11:47:32
Event loop events are enqueued until they are proc
| |
314 * yet. | |
301 * | 315 * |
302 * If [resumeCapability] is provided, it is used to identity the pause, | 316 * If [resumeCapability] is provided, it is used to identity the pause, |
303 * and must be used again to end the pause using [resume]. | 317 * and must be used again to end the pause using [resume]. |
304 * Otherwise a new resume capability is created and returned. | 318 * Otherwise a new resume capability is created and returned. |
305 * | 319 * |
306 * If an isolate is paused more than once using the same capability, | 320 * If an isolate is paused more than once using the same capability, |
307 * only one resume with that capability is needed to end the pause. | 321 * only one resume with that capability is needed to end the pause. |
308 * | 322 * |
309 * If an isolate is paused using more than one capability, | 323 * If an isolate is paused using more than one capability, |
310 * they must all be individully ended before the isolate resumes. | 324 * they must all be individully ended before the isolate resumes. |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 * as the original error, but has no other features of the original error. | 670 * as the original error, but has no other features of the original error. |
657 */ | 671 */ |
658 class RemoteError implements Error { | 672 class RemoteError implements Error { |
659 final String _description; | 673 final String _description; |
660 final StackTrace stackTrace; | 674 final StackTrace stackTrace; |
661 RemoteError(String description, String stackDescription) | 675 RemoteError(String description, String stackDescription) |
662 : _description = description, | 676 : _description = description, |
663 stackTrace = new StackTrace.fromString(stackDescription); | 677 stackTrace = new StackTrace.fromString(stackDescription); |
664 String toString() => _description; | 678 String toString() => _description; |
665 } | 679 } |
OLD | NEW |