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

Unified Diff: sdk/lib/isolate/isolate_stream.dart

Issue 20703003: Proposal for new Isolate library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/isolate/isolate.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/isolate/isolate_stream.dart
diff --git a/sdk/lib/isolate/isolate_stream.dart b/sdk/lib/isolate/isolate_stream.dart
deleted file mode 100644
index 922f6f9880ec07bdb44ff175aa88a484d654cd7f..0000000000000000000000000000000000000000
--- a/sdk/lib/isolate/isolate_stream.dart
+++ /dev/null
@@ -1,156 +0,0 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
-// 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.
-
-part of dart.isolate;
-
-/**
- * The initial IsolateStream available by default for this isolate.
- *
- * This IsolateStream is created automatically and is commonly used
- * to establish the first communication between isolates.
- * (See [streamSpawnFunction].)
- */
-final IsolateStream stream = new IsolateStream._fromOriginalReceivePort(port);
-
-/**
- * The creator of the [IsolateStream] and [IsolateSink]
- * that allow an isolate to exchange messages with other isolates.
- *
- * Any message that is written into the [sink] (independent of the isolate) is
- * sent to the [stream] where its subscribers can react to the messages.
- */
-class MessageBox {
- final IsolateStream stream;
- final IsolateSink sink;
-
- external MessageBox.oneShot();
- external MessageBox();
-}
-
-external bool _isCloseToken(var object);
-
-/**
- * Together with [IsolateSink], the only means of
- * communication between isolates.
- *
- * Each IsolateStream has a corresponding
- * [IsolateSink]. Any message written into that sink will be delivered to
- * the stream and then dispatched to the stream's subscribers.
- */
-class IsolateStream extends Stream<dynamic> {
- bool _isClosed = false;
- final ReceivePort _port;
- StreamController _controller = new StreamController(sync: true);
-
- IsolateStream._fromOriginalReceivePort(this._port) {
- _port.receive((message, replyTo) {
- assert(replyTo == null);
- _add(message);
- });
- }
-
- IsolateStream._fromOriginalReceivePortOneShot(this._port) {
- _port.receive((message, replyTo) {
- assert(replyTo == null);
- _add(message);
- close();
- });
- }
-
- void _add(var message) {
- if (_isCloseToken(message)) {
- close();
- } else {
- _controller.sink.add(message);
- }
- }
-
- /**
- * Closes the stream from the receiving end.
- *
- * Closing an already closed port has no effect.
- */
- void close() {
- if (!_isClosed) {
- _isClosed = true;
- _port.close();
- _controller.close();
- }
- }
-
- StreamSubscription listen(void onData(event),
- { void onError(error),
- void onDone(),
- bool cancelOnError}) {
- return _controller.stream.listen(onData,
- onError: onError,
- onDone: onDone,
- cancelOnError: cancelOnError);
- }
-}
-
-/**
- * The feed for an [IsolateStream].
- *
- * Any message written to [this] is delivered
- * to its respective [IsolateStream].
- * [IsolateSink]s are created by [MessageBox]es.
- *
- * [IsolateSink]s can be transmitted to other isolates.
- */
-abstract class IsolateSink extends EventSink<dynamic> {
- // TODO(floitsch): Actually it should be a StreamSink (being able to flow-
- // control).
-
- /**
- * Sends an asynchronous [message] to the linked [IsolateStream];
- * the message is copied to the receiving isolate.
- *
- * The content of [message] can be: primitive values (null, num, bool, double,
- * String), instances of [IsolateSink]s, and lists and maps whose elements are
- * any of these. List and maps are also allowed to be cyclic.
- *
- * In the special circumstances when two isolates share the same code and are
- * running in the same process (e.g. isolates created via [spawnFunction]), it
- * is also possible to send object instances (which would be copied in the
- * process). This is currently only supported by the dartvm. For now, the
- * dart2js compiler only supports the restricted messages described above.
- */
- void add(dynamic message);
-
- void addError(errorEvent);
-
- /** Closing multiple times is allowed. */
- void close();
-
- /**
- * Tests whether [other] is an [IsolateSink] feeding into the same
- * [IsolateStream] as this one.
- */
- bool operator==(var other);
-}
-
-
-/**
- * Creates and spawns an isolate that shares the same code as the current
- * isolate, but that starts from the specified function.
- *
- * The [topLevelFunction] argument must be
- * a static top-level function or a static method that takes no arguments.
- *
- * When any isolate starts (even the main script of the application), a default
- * [IsolateStream] is created for it. This sink is available from the top-level
- * getter [stream] defined in this library.
- *
- * [spawnFunction] returns an [IsolateSink] feeding into the child isolate's
- * default stream.
- *
- * The optional [unhandledExceptionCallback] argument is invoked whenever an
- * exception inside the isolate is unhandled. It can be seen as a big
- * `try/catch` around everything that is executed inside the isolate. The
- * callback should return `true` if it was able to handle the exception.
- */
-external IsolateSink streamSpawnFunction(
- void topLevelFunction(),
- [bool unhandledExceptionCallback(IsolateUnhandledException e)]);
« no previous file with comments | « sdk/lib/isolate/isolate.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698