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

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

Issue 179823002: Add Isolate.onExit. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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
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 /** 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 *
(...skipping 18 matching lines...) Expand all
29 } 29 }
30 30
31 class Isolate { 31 class Isolate {
32 /** 32 /**
33 * Control port used to send control messages to the isolate. 33 * Control port used to send control messages to the isolate.
34 * 34 *
35 * This class provides helper functions that sends control messages 35 * This class provides helper functions that sends control messages
36 * to the control port. 36 * to the control port.
37 */ 37 */
38 final SendPort controlPort; 38 final SendPort controlPort;
39 /**
40 * Capability granting the ability to pause the isolate.
41 */
39 final Capability pauseCapability; 42 final Capability pauseCapability;
43 /**
44 * Capability granting the ability to inspect the isolate.
45 *
46 * This capability is needed to be able to see uncaught errors and exit of
47 * the isolate.
floitsch 2014/02/25 19:25:48 I don't think inspecting is the same as being able
Lasse Reichstein Nielsen 2014/02/27 08:04:28 Would "observe" be a better word. It suggests a mo
48 */
49 final Capability inspectCapability;
40 50
41 Isolate._fromControlPort(this.controlPort, [this.pauseCapability]); 51 Isolate._fromControlPort(this.controlPort, [this.pauseCapability,
52 this.inspectCapability]);
42 53
43 /** 54 /**
44 * Creates and spawns an isolate that shares the same code as the current 55 * Creates and spawns an isolate that shares the same code as the current
45 * isolate. 56 * isolate.
46 * 57 *
47 * The argument [entryPoint] specifies the entry point of the spawned 58 * The argument [entryPoint] specifies the entry point of the spawned
48 * isolate. It must be a top-level function or a static method that 59 * isolate. It must be a top-level function or a static method that
49 * takes one argument - that is, one-parameter functions that can be 60 * takes one argument - that is, one-parameter functions that can be
50 * compile-time constant function values. 61 * compile-time constant function values.
51 * It is not allowed to pass the value of function expressions or an instance 62 * It is not allowed to pass the value of function expressions or an instance
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 * 100 *
90 * The isolate should stop handling events by pausing its event queue. 101 * The isolate should stop handling events by pausing its event queue.
91 * The request will eventually make the isolate stop doing anything. 102 * The request will eventually make the isolate stop doing anything.
92 * It will be handled before any other messages sent to the isolate from 103 * It will be handled before any other messages sent to the isolate from
93 * the current isolate, but no other guarantees are provided. 104 * the current isolate, but no other guarantees are provided.
94 * 105 *
95 * If [resumeCapability] is provided, it is used to identity the pause, 106 * If [resumeCapability] is provided, it is used to identity the pause,
96 * and must be used again to end the pause using [resume]. 107 * and must be used again to end the pause using [resume].
97 * Otherwise a new capability is created and returned. 108 * Otherwise a new capability is created and returned.
98 * 109 *
99 * If an isolate is paused more than once using the same capabilty, 110 * If an isolate is paused more than once using the same capability,
100 * only one resume with that capability is needed to end the pause. 111 * only one resume with that capability is needed to end the pause.
101 * 112 *
102 * If an isolate is paused using more than one capability, 113 * If an isolate is paused using more than one capability,
103 * they must all be individully ended before the isolate resumes. 114 * they must all be individully ended before the isolate resumes.
104 * 115 *
105 * Returns the capability that must be used to resume end the pause. 116 * Returns the capability that must be used to resume end the pause.
106 * 117 *
107 * WARNING: This method is not handled on any platform yet. 118 * WARNING: This method is not handled on any platform yet.
108 */ 119 */
109 Capability pause([Capability resumeCapability]) { 120 Capability pause([Capability resumeCapability]) {
(...skipping 16 matching lines...) Expand all
126 * isolate, otherwise the resume call does nothing. 137 * isolate, otherwise the resume call does nothing.
127 * 138 *
128 * WARNING: This method is not handled on any platform yet. 139 * WARNING: This method is not handled on any platform yet.
129 */ 140 */
130 void resume(Capability resumeCapability) { 141 void resume(Capability resumeCapability) {
131 var message = new List(2) 142 var message = new List(2)
132 ..[0] = "resume" 143 ..[0] = "resume"
133 ..[1] = resumeCapability; 144 ..[1] = resumeCapability;
134 controlPort.send(message); 145 controlPort.send(message);
135 } 146 }
147
148 /**
149 * Returns a future that completes after the isolate has terminated.
150 */
151 Future get onExit {
152 // Should we return a broadcast stream instead? It has the advantage
floitsch 2014/02/25 19:25:48 I don't see any stream.
Lasse Reichstein Nielsen 2014/02/27 08:04:28 No, I was suggesting a broadcast stream instead of
153 // that you can stop listening again.
154 var completer = new Completer();
155 var receivePort;
156 receivePort = new RawReceivePort((_) {
157 completer.complete();
158 receivePort.close();
159 });
160 var message = new List(3)
161 ..[0] = "ondone"
162 ..[1] = inspectCapability
163 ..[2] = receivePort.sendPort;
164 controlPort.send(message);
165 return completer.future;
166 }
136 } 167 }
137 168
138 /** 169 /**
139 * Sends messages to its [ReceivePort]s. 170 * Sends messages to its [ReceivePort]s.
140 * 171 *
141 * [SendPort]s are created from [ReceivePort]s. Any message sent through 172 * [SendPort]s are created from [ReceivePort]s. Any message sent through
142 * a [SendPort] is delivered to its corresponding [ReceivePort]. There might be 173 * a [SendPort] is delivered to its corresponding [ReceivePort]. There might be
143 * many [SendPort]s for the same [ReceivePort]. 174 * many [SendPort]s for the same [ReceivePort].
144 * 175 *
145 * [SendPort]s can be transmitted to other isolates. 176 * [SendPort]s can be transmitted to other isolates.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 const _IsolateUnhandledException(this.message, this.source, this.stackTrace); 322 const _IsolateUnhandledException(this.message, this.source, this.stackTrace);
292 323
293 String toString() { 324 String toString() {
294 return 'IsolateUnhandledException: exception while handling message: ' 325 return 'IsolateUnhandledException: exception while handling message: '
295 '${message} \n ' 326 '${message} \n '
296 '${source.toString().replaceAll("\n", "\n ")}\n' 327 '${source.toString().replaceAll("\n", "\n ")}\n'
297 'original stack trace:\n ' 328 'original stack trace:\n '
298 '${stackTrace.toString().replaceAll("\n","\n ")}'; 329 '${stackTrace.toString().replaceAll("\n","\n ")}';
299 } 330 }
300 } 331 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698