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. | 5 // Dart core library. |
6 | 6 |
7 /** | 7 /** |
8 * [SendPort]s are created from [ReceivePort]s. Any message sent through | 8 * [SendPort]s are created from [ReceivePort]s. Any message sent through |
9 * a [SendPort] is delivered to its respective [ReceivePort]. There might be | 9 * a [SendPort] is delivered to its respective [ReceivePort]. There might be |
10 * many [SendPort]s for the same [ReceivePort]. | 10 * many [SendPort]s for the same [ReceivePort]. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 /** | 130 /** |
131 * Spawns a new isolate, using this instance as template. | 131 * Spawns a new isolate, using this instance as template. |
132 * | 132 * |
133 * The new isolate lives in a new thread (for heavy templates) | 133 * The new isolate lives in a new thread (for heavy templates) |
134 * or in the same thread as the current isolate (for light templates), if | 134 * or in the same thread as the current isolate (for light templates), if |
135 * possible. | 135 * possible. |
136 * | 136 * |
137 * During the initialization of the new isolate a [ReceivePort] is created | 137 * During the initialization of the new isolate a [ReceivePort] is created |
138 * inside the new isolate and stored in [port]. A corresponding | 138 * inside the new isolate and stored in [port]. A corresponding |
139 * [SendPort] is sent to the isolate that invoked [spawn]. Since spawning an | 139 * [SendPort] is sent to the isolate that invoked [spawn]. Since spawning an |
140 * isolate is an asynchronous operation this method returns a [Promise] of | 140 * isolate is an asynchronous operation this method returns a [Future] of |
141 * this [SendPort]. | 141 * this [SendPort]. |
142 * | 142 * |
143 * A common pattern to instantiate new isolates is to enqueue the instructions | 143 * A common pattern to instantiate new isolates is to enqueue the instructions |
144 * in [Promise.then]. | 144 * in [Future.then]. |
145 * [:myIsolate.spawn().then((SendPort port) { port.send('hi there'); });:] | 145 * [:myIsolate.spawn().then((SendPort port) { port.send('hi there'); });:] |
146 */ | 146 */ |
147 Promise<SendPort> spawn() { | 147 Future<SendPort> spawn() { |
148 return IsolateNatives.spawn(this, _isLight); | 148 return IsolateNatives.spawn(this, _isLight); |
149 } | 149 } |
150 | 150 |
151 // The private run method is invoked with the receive port. Before | 151 // The private run method is invoked with the receive port. Before |
152 // main is invoked we store the port in a field so it can be | 152 // main is invoked we store the port in a field so it can be |
153 // accessed from subclasses of Isolate. | 153 // accessed from subclasses of Isolate. |
154 void _run(ReceivePort port) { | 154 void _run(ReceivePort port) { |
155 _port = port; | 155 _port = port; |
156 main(); | 156 main(); |
157 } | 157 } |
(...skipping 13 matching lines...) Expand all Loading... |
171 /** | 171 /** |
172 * When isolates are created, an instance of the template's class is | 172 * When isolates are created, an instance of the template's class is |
173 * instantiated in the new isolate. After the [port] has been set up, this | 173 * instantiated in the new isolate. After the [port] has been set up, this |
174 * [main] method is invoked on the instance. | 174 * [main] method is invoked on the instance. |
175 */ | 175 */ |
176 abstract void main(); | 176 abstract void main(); |
177 | 177 |
178 final bool _isLight; | 178 final bool _isLight; |
179 ReceivePort _port; | 179 ReceivePort _port; |
180 } | 180 } |
OLD | NEW |