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

Side by Side Diff: sdk/lib/isolate/base.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | « sdk/lib/io/websocket_impl.dart ('k') | sdk/lib/isolate/isolate.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) 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 part of dart.isolate; 5 part of dart.isolate;
6 6
7 class IsolateSpawnException implements Exception { 7 class IsolateSpawnException implements Exception {
8 const IsolateSpawnException(String this._s); 8 const IsolateSpawnException(String this._s);
9 String toString() => "IsolateSpawnException: '$_s'"; 9 String toString() => "IsolateSpawnException: '$_s'";
10 final String _s; 10 final String _s;
11 } 11 }
12 12
13 /** 13 /**
14 * The initial [ReceivePort] available by default for this isolate. This 14 * The initial [ReceivePort] available by default for this isolate. This
15 * [ReceivePort] is created automatically and it is commonly used to establish 15 * [ReceivePort] is created automatically and it is commonly used to establish
16 * the first communication between isolates (see [spawnFunction] and 16 * the first communication between isolates (see [spawnFunction] and
17 * [spawnUri]). 17 * [spawnUri]).
18 */ 18 */
19 external ReceivePort get port; 19 ReceivePort get port => _Isolate.port;
20 20
21 /** 21 /**
22 * Creates and spawns an isolate that shares the same code as the current 22 * Creates and spawns an isolate that shares the same code as the current
23 * isolate, but that starts from [topLevelFunction]. The [topLevelFunction] 23 * isolate, but that starts from [topLevelFunction]. The [topLevelFunction]
24 * argument must be a static top-level function or a static method that takes no 24 * argument must be a static top-level function or a static method that takes no
25 * arguments. It is illegal to pass a function closure. 25 * arguments. It is illegal to pass a function closure.
26 * 26 *
27 * When any isolate starts (even the main script of the application), a default 27 * When any isolate starts (even the main script of the application), a default
28 * [ReceivePort] is created for it. This port is available from the top-level 28 * [ReceivePort] is created for it. This port is available from the top-level
29 * getter [port] defined in this library. 29 * getter [port] defined in this library.
30 * 30 *
31 * [spawnFunction] returns a [SendPort] derived from the child isolate's default 31 * [spawnFunction] returns a [SendPort] derived from the child isolate's default
32 * port. 32 * port.
33 * 33 *
34 * See comments at the top of this library for more details. 34 * See comments at the top of this library for more details.
35 */ 35 */
36 // Note this feature is not yet available in the dartvm. 36 SendPort spawnFunction(void topLevelFunction(),
37 external SendPort spawnFunction(void topLevelFunction(), 37 [bool UnhandledExceptionCallback(IsolateUnhandledException e)])
38 [bool UnhandledExceptionCallback(IsolateUnhandledException e)]); 38 => _Isolate.spawnFunction(topLevelFunction, UnhandledExceptionCallback);
39
39 /** 40 /**
40 * Creates and spawns an isolate whose code is available at [uri]. Like with 41 * Creates and spawns an isolate whose code is available at [uri]. Like with
41 * [spawnFunction], the child isolate will have a default [ReceivePort], and a 42 * [spawnFunction], the child isolate will have a default [ReceivePort], and a
42 * this function returns a [SendPort] derived from it. 43 * this function returns a [SendPort] derived from it.
43 * 44 *
44 * See comments at the top of this library for more details. 45 * See comments at the top of this library for more details.
45 */ 46 */
46 external SendPort spawnUri(String uri); 47 SendPort spawnUri(String uri) => _Isolate.spawnUri(uri);
47 48
48 /** 49 /**
49 * [SendPort]s are created from [ReceivePort]s. Any message sent through 50 * [SendPort]s are created from [ReceivePort]s. Any message sent through
50 * a [SendPort] is delivered to its respective [ReceivePort]. There might be 51 * a [SendPort] is delivered to its respective [ReceivePort]. There might be
51 * many [SendPort]s for the same [ReceivePort]. 52 * many [SendPort]s for the same [ReceivePort].
52 * 53 *
53 * [SendPort]s can be transmitted to other isolates. 54 * [SendPort]s can be transmitted to other isolates.
54 */ 55 */
55 abstract class SendPort { 56 abstract class SendPort {
56 57
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 139
139 } 140 }
140 141
141 // TODO(kasperl): Document this. 142 // TODO(kasperl): Document this.
142 abstract class SendPortSync { 143 abstract class SendPortSync {
143 144
144 callSync(var message); 145 callSync(var message);
145 146
146 } 147 }
147 148
149 // The VM doesn't support accessing external globals in the same library. We
150 // therefore create this wrapper class.
151 // TODO(6997): Don't go through static class for external variables.
152 abstract class _Isolate {
153 external static ReceivePort get port;
154 external static SendPort spawnFunction(void topLevelFunction(),
155 [bool UnhandledExceptionCallback(IsolateUnhandledException e)]);
156 external static SendPort spawnUri(String uri);
157 }
158
148 /** 159 /**
149 * Wraps unhandled exceptions thrown during isolate execution. It is 160 * Wraps unhandled exceptions thrown during isolate execution. It is
150 * used to show both the error message and the stack trace for unhandled 161 * used to show both the error message and the stack trace for unhandled
151 * exceptions. 162 * exceptions.
152 */ 163 */
153 class IsolateUnhandledException implements Exception { 164 class IsolateUnhandledException implements Exception {
154 /** Message being handled when exception occurred. */ 165 /** Message being handled when exception occurred. */
155 final message; 166 final message;
156 167
157 /** Wrapped exception. */ 168 /** Wrapped exception. */
158 final source; 169 final source;
159 170
160 /** Trace for the wrapped exception. */ 171 /** Trace for the wrapped exception. */
161 final Object stackTrace; 172 final Object stackTrace;
162 173
163 const IsolateUnhandledException(this.message, this.source, this.stackTrace); 174 const IsolateUnhandledException(this.message, this.source, this.stackTrace);
164 175
165 String toString() { 176 String toString() {
166 return 'IsolateUnhandledException: exception while handling message: ' 177 return 'IsolateUnhandledException: exception while handling message: '
167 '${message} \n ' 178 '${message} \n '
168 '${source.toString().replaceAll("\n", "\n ")}\n' 179 '${source.toString().replaceAll("\n", "\n ")}\n'
169 'original stack trace:\n ' 180 'original stack trace:\n '
170 '${stackTrace.toString().replaceAll("\n","\n ")}'; 181 '${stackTrace.toString().replaceAll("\n","\n ")}';
171 } 182 }
172 } 183 }
OLDNEW
« no previous file with comments | « sdk/lib/io/websocket_impl.dart ('k') | sdk/lib/isolate/isolate.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698