| Index: lib/isolate/isolate_api.dart
|
| diff --git a/corelib/src/isolate.dart b/lib/isolate/isolate_api.dart
|
| similarity index 78%
|
| rename from corelib/src/isolate.dart
|
| rename to lib/isolate/isolate_api.dart
|
| index 09c3ab047ff0234c4fd3fe9688ff867cdf4e2418..8cc85e71f0e9f2bb4d8fdb1c64db7e830f30b27b 100644
|
| --- a/corelib/src/isolate.dart
|
| +++ b/lib/isolate/isolate_api.dart
|
| @@ -2,9 +2,6 @@
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| -// Dart core library.
|
| -// TODO(sigmund): move to dart:isolate
|
| -
|
| /**
|
| * [SendPort]s are created from [ReceivePort]s. Any message sent through
|
| * a [SendPort] is delivered to its respective [ReceivePort]. There might be
|
| @@ -55,7 +52,7 @@ interface SendPort extends Hashable {
|
| *
|
| * A [ReceivePort] may have many [SendPort]s.
|
| */
|
| -interface ReceivePort default ReceivePortFactory {
|
| +interface ReceivePort default _ReceivePortFactory {
|
|
|
| /**
|
| * Opens a long-lived port for receiving messages. The returned port
|
| @@ -147,7 +144,7 @@ class Isolate {
|
| * [:myIsolate.spawn().then((SendPort port) { port.send('hi there'); });:]
|
| */
|
| Future<SendPort> spawn() {
|
| - return IsolateNatives.spawn(this, _isLight);
|
| + return _IsolateNatives.spawn(this, _isLight);
|
| }
|
|
|
| // The private run method is invoked with the receive port. Before
|
| @@ -180,3 +177,39 @@ class Isolate {
|
| final bool _isLight;
|
| ReceivePort _port;
|
| }
|
| +
|
| +/**
|
| + * [Isolate2] provides APIs to spawn, communicate, and stop an isolate. An
|
| + * isolate can be spawned by simply creating a new instance of [Isolate2]. The
|
| + * [Isolate2] instance exposes a port to communicate with the isolate and
|
| + * methods to control its behavior remotely.
|
| + */
|
| + // TODO(sigmund): rename to Isolate once we delete the old implementation
|
| +interface Isolate2 default _IsolateFactory {
|
| +
|
| + /**
|
| + * Create and spawn an isolate that shares the same code as the current
|
| + * isolate, but that starts from [topLevelFunction]. The [topLevelFunction]
|
| + * argument must be a static method closure that takes exactly one
|
| + * argument of type [ReceivePort]. It is illegal to pass a function closure
|
| + * that captures values in scope.
|
| + *
|
| + * When an child isolate is spawned, a new [ReceivePort] is created for it.
|
| + * This port is passed to [topLevelFunction]. A [SendPort] derived from
|
| + * such port is sent to the spawner isolate, which is accessible in
|
| + * [Isolate2.sendPort] field of this instance.
|
| + */
|
| + Isolate2.fromCode(Function topLevelFunction);
|
| +
|
| + /**
|
| + * Create and spawn an isolate whose code is available at [uri].
|
| + * The code in [uri] must have an method called [: isolateMain :], which takes
|
| + * exactly one argument of type [ReceivePort].
|
| + * Like with [Isolate2.fromCode], a [ReceivePort] is created in the child
|
| + * isolate, and a [SendPort] to it is stored in [Isolate2.sendPort].
|
| + */
|
| + Isolate2.fromUri(String uri);
|
| +
|
| + /** Port used to communicate with this isolate. */
|
| + SendPort sendPort;
|
| +}
|
|
|