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

Unified Diff: mojo/public/dart/src/event_stream.dart

Issue 982673002: Dart: Removes need to call listen(). (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Don't pile up callbacks Created 5 years, 10 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 | « mojo/public/dart/src/codec.dart ('k') | mojo/public/dart/src/proxy.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/dart/src/event_stream.dart
diff --git a/mojo/public/dart/src/event_stream.dart b/mojo/public/dart/src/event_stream.dart
index c1251140acaaefd870bf0e18085337e16cf8a879..7643ac71c7ed8bb4bcd21032b56cd41219e15c27 100644
--- a/mojo/public/dart/src/event_stream.dart
+++ b/mojo/public/dart/src/event_stream.dart
@@ -123,9 +123,7 @@ class MojoEventStream extends Stream<List<int>> {
String toString() => "$_handle";
}
-abstract class Listener {
- StreamSubscription<List<int>> listen({Function onClosed});
-}
+typedef void ErrorHandler();
class MojoEventStreamListener {
MojoMessagePipeEndpoint _endpoint;
@@ -133,25 +131,20 @@ class MojoEventStreamListener {
bool _isOpen = false;
bool _isInHandler = false;
StreamSubscription subscription;
+ ErrorHandler onError;
- MojoEventStreamListener.fromEndpoint(MojoMessagePipeEndpoint endpoint,
- {bool doListen: true, Function onClosed})
+ MojoEventStreamListener.fromEndpoint(MojoMessagePipeEndpoint endpoint)
hansmuller1 2015/03/06 17:12:38 We've run into the need for |doListen: false| when
zra 2015/03/06 21:12:00 Scott pointed out that it is okay to wait to set i
: _endpoint = endpoint,
_eventStream = new MojoEventStream(endpoint.handle),
_isOpen = false {
- if (doListen) {
- listen(onClosed: onClosed);
- }
+ listen();
}
- MojoEventStreamListener.fromHandle(MojoHandle handle, {bool doListen: true,
- Function onClosed}) {
+ MojoEventStreamListener.fromHandle(MojoHandle handle) {
_endpoint = new MojoMessagePipeEndpoint(handle);
_eventStream = new MojoEventStream(handle);
_isOpen = false;
- if (doListen) {
- listen(onClosed: onClosed);
- }
+ listen();
}
MojoEventStreamListener.unbound()
@@ -173,7 +166,7 @@ class MojoEventStreamListener {
_isOpen = false;
}
- StreamSubscription<List<int>> listen({Function onClosed}) {
+ StreamSubscription<List<int>> listen() {
assert(isBound && (subscription == null));
_isOpen = true;
subscription = _eventStream.listen((List<int> event) {
@@ -193,7 +186,7 @@ class MojoEventStreamListener {
}
_isInHandler = false;
if (signalsReceived.isPeerClosed) {
- if (onClosed != null) onClosed();
+ if (onError != null) onError();
close();
// The peer being closed obviates any other signal we might
// have received since we won't be able to read or write the handle.
« no previous file with comments | « mojo/public/dart/src/codec.dart ('k') | mojo/public/dart/src/proxy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698