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

Unified Diff: lib/src/multiplexport.dart

Issue 1025293003: pkg/isolate: library renaming, removed unused method, fix creation of TimeoutException (Closed) Base URL: https://github.com/dart-lang/isolate.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
Index: lib/src/multiplexport.dart
diff --git a/lib/src/multiplexport.dart b/lib/src/multiplexport.dart
deleted file mode 100644
index 2711c45752e21c874ecf72b10b560f4d26a18878..0000000000000000000000000000000000000000
--- a/lib/src/multiplexport.dart
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright (c) 2015, 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.
-
-/// A multiplexing [RawReceivePort].
-///
-/// Allows creating a number of [RawReceivePort] implementations that all send
-/// messages through the same real `RawReceivePort`.
-///
-/// This allows reducing the number of receive ports created, but adds an
-/// overhead to each message.
-/// If a library creates many short-lived receive ports, multiplexing might be
-/// faster.
-///
-/// To use multiplexing receive ports, create and store a
-/// [RawReceivePortMultiplexer], and create receive ports by calling
-/// `multiplexer.createRawReceivePort(handler)` where you would otherwise
-/// write `new RawReceivePort(handler)`.
-///
-/// Remember to [close] the multiplexer when it is no longer needed.
-/// `
-/// (TODO: Check if it really is faster - creating a receive port requires a
-/// global mutex, so it may be a bottleneck, but it's not clear how slow it is).
-library pkg.isolate.multiplexreceiveport;
-
-import "dart:isolate";
-import "dart:collection";
-import "lists.dart";
-
-class _MultiplexRawReceivePort implements RawReceivePort {
- final RawReceivePortMultiplexer _multiplexer;
- final int _id;
- Function _handler;
-
- _MultiplexRawReceivePort(this._multiplexer, this._id, this._handler);
-
- void set handler(void handler(response)) {
- this._handler = handler;
- }
-
- void close() {
- _multiplexer._closePort(_id);
- }
-
- SendPort get sendPort => _multiplexer._createSendPort(_id);
-
- void _invokeHandler(message) {
- _handler(message);
- }
-}
-
-class _MultiplexSendPort implements SendPort {
- final SendPort _sendPort;
- final int _id;
- _MultiplexSendPort(this._id, this._sendPort);
-
- void send(message) {
- _sendPort.send(list2(_id, message));
- }
-}
-
-/// A shared [RawReceivePort] that distributes messages to
-/// [RawReceivePort] instances that it manages.
-class RawReceivePortMultiplexer {
- final RawReceivePort _port = new RawReceivePort();
- final Map<int, _MultiplexRawReceivePort> _map = new HashMap();
- int _nextId = 0;
-
- RawReceivePortMultiplexer() {
- _port.handler = _multiplexResponse;
- }
-
- RawReceivePort createRawReceivePort([void handler(value)]) {
- int id = _nextId++;
- var result = new _MultiplexRawReceivePort(this, id, handler);
- _map[id] = result;
- return result;
- }
-
- void close() {
- _port.close();
- }
-
- void _multiplexResponse(list) {
- int id = list[0];
- var message = list[1];
- _MultiplexRawReceivePort receivePort = _map[id];
- // If the receive port is closed, messages are dropped, just as for
- // the normal ReceivePort.
- if (receivePort == null) return; // Port closed.
- receivePort._invokeHandler(message);
- }
-
- SendPort _createSendPort(int id) {
- return new _MultiplexSendPort(id, _port.sendPort);
- }
-
- void _closePort(int id) {
- _map.remove(id);
- }
-}

Powered by Google App Engine
This is Rietveld 408576698